View Antoni Milton's profile on LinkedIn

Thursday, October 14, 2010

In Linux anything is equivalent to windows registry?

I saw the questions in many Linux forums

The RPM package information stored in the below location

/var/lib/rpm
[root@hostrpm]# ls
Basenames     __db.000  __db.002  Dirnames  Group       Name      Providename     Pubkeys      Requireversion  Sigmd5
Conflictname  __db.001  __db.003  Filemd5s  Installtid  Packages  Provideversion  Requirename  Sha1header      Triggername

It uses Berkeley DB as its back-end. It consists of a single database (Packages) containing all of the meta information of the installed rpms.
The RPM database is used to keep track of all files that are changed and created when a user installs a package. If the database gets corrupted, the index databases can be recreated with the rpm --rebuilddb command.

If you issues the rpm- qa ( query ) command then, it will read from the DB and list out the package names.

If you delete the installation directory directly, it won’t delete the record from the RPM DB. For that you need to execute the rpm –ivh (uninstall ) command , otherwise you can’t install the same package.

Thursday, July 8, 2010

How to check CPU and memory Hardware detials in RHEL system?

Using the bellow command, we can see the Memory and CPU related hardware details

#cat  /proc/meminfo


#cat  /proc/cpuinfo

Wednesday, June 9, 2010

How to write / setup SCTP client server program in RHEL system?

Setup:

Before run any SCTP application, we need to install SCTP libs from

http://lksctp.sourceforge.net/

Using the below command, register the SCTP module into kernel.

#modprobe sctp

http://linux.about.com/od/commands/l/blcmdl8_modprob.htm


SCTP Application writing:-


SCTP client and server system call follow same as TCP. ( like socket,bind,listen and accept )

Creating SCTP socket

Sock = socket( AF_INET, SOCK_STREAM, IPPROTO_SCTP );

Before listen, we need to set the value for the no.of stream for the socket using setsockopt system call.

struct sctp_initmsg startupsctp;

startupsctp.sinit_num_ostreams = 3;

startupsctp.sinit_max_instreams = 3;

startupsctp.sinit_max_attempts = 4;

ret = setsockopt( listen_Socket, IPPROTO_SCTP, SCTP_INITMSG, & startupsctp, sizeof(startupsctp) );

Using sctp_sendmsg() and sctp_recvmsg() system calls , we can send/receive data over the SCTP socket.


Example code:-

Please refer : http://www.ibm.com/developerworks/linux/library/l-sctp/

Tuesday, May 25, 2010

How to decompress the tar.bz2 format file?

#tar -xvjf xxxx.tar.bz2
tmp/test.txt

Options:

* x - extract
* c - create to create
* v - verbose
* z - gzip
* j - bzip2 ( .bz2 )
* f - file name ( after the “f” indicate the input/output file name )

Monday, April 5, 2010

How to prepare ISO image and test it?

An ISO image is an archive file/disc image of an optical disc in a format defined by the International Organization for Standardization (ISO). ISO image files typically have a file extension of .iso

Create folder name with "
cd"

#mkdir
cd
#cd
cd

copy your application/package/rpm/script file into the folder
#cp /root/test/Add-lnx26.sh .
#ls
Add-lnx26.sh

run the below command for creating the iso image with the name of add.iso

#cd ..

#mkisofs -l -r -N -d -D -J -o add.iso -V "Add-1.0" -A "Add program for ISO image test" cd

Warning: creating filesystem that does not conform to ISO-9660.
Total translation table size: 0
Total rockridge attributes bytes: 247
Total directory bytes: 0
Path table size(bytes): 10
Max brk space used c000
182 extents written (0 MB)

#ls
cd add.iso



Monday, March 29, 2010

How to find the particular package installed or not?

Using “rpm –qa ” command, we can find whether the package installed or not.


Below shell script use the command for determine the given string/name package rpm installed or not installed.

############

rpmcheck.sh

############

#!/bin/bash
rpm -qa "*$1*" > r1
line_no=$( wc -l < r1 )
echo "$line_no"
if [ $line_no == 0 ]
then
echo "rpm not installed "
else
echo "rpm installed "
fi


Output:

[root@home linux]# ./rpmcheck.sh milton
0
rpm not installed
[root@home linux]# ./rpmcheck.sh boost
2
rpm installed

How to find which rpm (package) install the particular file?


Using “rpm –qf” command, we can find the rpm package name for the lib file.

Example:

[root@home linux]# rpm -qf /usr/lib/libpython2.3.so
python-2.3.4-14.1

[root@home linux]# rpm -qf /usr/include/boost/blank.hpp
boost-devel-1.32.0-1.rhel4

Sunday, March 14, 2010

How to check the given string is valid IPAddress or Domain Name?

Using inet_pton function we can determine, whether given string is a valid IPv4/v6 Address or Domain name.

In below example,

first check the given string is a valid Ipv4 address not then check valid Ipv6 address and check the input string as a valid domain name.

int CheckIPAddress( const char* pszHostName)
{
int iResult =0; // 1 - Ipv4,2-Ipv6, 3- domain name, 0-invalid ip

struct sockaddr_in sockAddr;
struct in_addr addr;
struct in6_addr aadrv6;
struct hostent *host;
int iTemp = inet_pton(AF_INET, pszHostName, &(sockAddr.sin_addr));
if( iTemp == 1 ) // vaild IPv4 Address
{
iResult = 1;
}
else if( inet_pton(AF_INET6,pszHostName,&aadrv6 ) == 1)
{
iResult = 2;
}
else // may be a domain name. try convert in to Ipv4 Address
{
if (( host = gethostbyname( pszHostName )) != NULL )
{
addr.s_addr = *(u_long *) host->h_addr_list[0];
printf("IPAddress: %s\n", inet_ntoa( addr) );
iResult = 3;
}
}
return iResult;
}

Thursday, March 11, 2010

How to convert domain name to IPAddress in C++?

Using the gethostbyname() system call we can get the IPAddress from domain name. Below given example program , convert the domain name to IPAddress and print the IPAddress in "." format ( xxx.xxx.xxx.xxx. )

#include "stdio.h"
#include "sys/types.h"
#include "sys/socket.h"
#include "netdb.h"
#include "netinet/in.h"
#include "arpa/inet.h"

int main(int argc,char * argv[])
{

struct hostent *host;
struct in_addr addr;
if( argc != 2 )
{
printf("usage: ./a.out "domainname" ");
return 0;
}


if ((host = gethostbyname(argv[1])) == NULL) {
printf("error resolving hostname..\n");
return -1;
}

addr.s_addr = *(u_long *) host->h_addr_list[0];
printf("IP: %s\n", inet_ntoa( addr ) );
return 0;
}

Tuesday, March 9, 2010

Track your expense in online – simple personal accounting online software

http://www.paisagate.com/index.htm

How to pass arguments for make file?

we can pass the arguments to makefile like below,

make -f Makefile HOST_OS="Linux"

in Makefile,we can use HOST_OS macro as usual.

example:

in main_folder make file,

HOST_OS = "SunOS"

all:
cd Sub_folder && make -f Makefile HOST_OS=$(HOST_OS)

in Sub_folder make file,

all:
ifeq ($(HOST_OS),Linux)
[ tab] g++ main.cpp
else
[tab] cc main.cpp
endif

Friday, February 26, 2010

How to check the directory exists or not from Makefile??

If the directory exists means, no need to untar the file.

setup:

if test -d DIR_NAME ; then echo NO NEED TO UNTAR ; else tar -xvf FILE.tar ; fi

Thursday, February 4, 2010

Singleton Design Pattern with example C++ code

The Singleton design pattern ensures only one instance of a class in an application. For example, Interfaces object need by both GUI and Back-end class. But only one interface object enough for the whole application (GUI + interface + Back-end)

Here need to develop the interface class as a Singleton class.

static CInterface *s_ptrInterface = 0;

class CInterface
{
private:
CInterface();
~ CInterface();
public:
static CInterface* getInterface()
{
 lock(); // for thread safe.
if( 0 != s_ptrInterface )
s_ptrInterface = new CInterface();
unlock();

return s_ptrInterface ;
}
}
Need to create the object for CInterface like below,
CInterface:: getInterface() // it’s always return the same object

Wednesday, February 3, 2010

Photograph Puzzle Maker

try this site,

http://www.flash-gear.com/npuz/

Tuesday, February 2, 2010

Object slicing example in C++

class Pet

{

string pname;

public:

Pet(const string& name) : pname(name) {}

virtual string name() const { return pname; }

virtual string description() const { return "This is " + pname; }

};


class Dog : public Pet

{

string favoriteActivity;

public:

Dog( const string& name, const string& activity): Pet(name), favoriteActivity(activity) {}

string description() const { return Pet::name() + " likes to " + favoriteActivity; }

};


void describe(Pet p)

{ // Slices the object

cout << p.description() << endl;

}


int main()

{

Pet p("Alfred");

Dog d("Fluffy", "sleep");

describe(p);

describe(d);

}