Pages

Wednesday, October 31, 2012

Let's see what you installed

Google+
To install packages in Linux:
Packages can be installed using yum, or rpm. Each one has it's own internal database that list what is already installed into the system.

To install a package using yum:
#yum install

To install a package using rpm:
#rpm -ivh
#rpm -Uvh

To check what is already installed:

To check what is yum installed:
#yum list | grep


To check what is rpm installed:
#rpm -qa | grep



HTH
--kongkon

Tuesday, October 23, 2012

How to grep in shell script...

The task is there is a file containing one column of entries. Write a script to compare the o/p of one command and check whether the output matches with any row of that file (supported.txt file).

$cat supported.txt
SAS2308_2(C1)
SAS2308_2(D1)

Assume $devInfo gives us a string that contains like the rows of support.txt file. If there is a match between the o/p of $devInfo in that file, then do nothing, else warn.

checkSupportedFwDev() {
        local supportedControllerList=`cat supported.txt`
        #Get the controller name from $devInfo and compare that with $supportedControllerList
        local currentController=`echo "${devInfo}" | grep "Controller" |grep -v Number | awk '{ print $NF }'`
        #echo "currentController=[$currentController]"
        local supported=`echo "${supportedControllerList}" | grep $currentController`
        if [ -z ${supported} ]
        then
                echo "Warning: This adapter [${currentController}] is not officially supported."
        fi
        }

Another approach to do the same:

checkSupportedFwDev() { 
        #Get the controller name from $devInfo and compare that with $supportedControllerList
        local currentController=`echo "${devInfo}" | grep "Controller" |grep -v Number | awk '{ print $NF }'`

        if ! grep "^${currentController}\$" supported.txt >/dev/null 2>&1;
        then
                echo "Warning: This adapter [${currentController}] is not officially supported."
        fi

}

Which approach you like and why?





Friday, October 12, 2012

Vi tricks

How to set the line numbers into vi editor?
Everyone knows this:
a) cd
-- go to home directory
b) edit(create if not there) a file called .exrc, and all this line
set nu
or set number
Simple.

But, what I al now looking at is how to set the vi line numbering in only a special work directory, say /home/kdutta/mywork. I do not want to set vi line numbering to all directories, at times this is annoying.
Putting a .exrc file into /home/kdutta/mywork/.exrc does not seem to work, here, even if I source it.

Do you know, how to do that?