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?

Thursday, September 27, 2012

Difference between $variable and ${variable} in (bash) shell scripting

Many often we do shell scripting, but small small ignorance at times cost a lot. Here is an example of what we mean and what it become.
[/tmp]$ cat try.sh #! /bin/sh a=12 b=34 echo $a_$b echo ${a}_$b [vivarkey@/tmp]$ sh try.sh 34 12_34 [/tmp]$


In the above shell script we intended to print "variableA_variableB", in the shell script on last but one line. But since we missed the braces around the variable it actually truncated the previous variable along with the '-' symbol.

NB: This code snippet is tried in bash shell on Linux, on mac it gives different result.

HTH
Kongkon

Playing with RPM

Ever wondered after running the rpm --install (or rpm -ivh) command what happened, what sort of files created in the file system.

To find out the list of files that an already installed rpm spawned:
rpm -ql
NB: there is no .rpm after the package name here in this command.

[root@localhost release]# rpm -qa|grep lsifw-tools-xrtx
lsifw-tools-xrtx-1-1.xrtx.1872.noarch
[root@localhost release]# rpm -ql lsifw-tools-xrtx-1-1.xrtx.1872.noarch
/lib/firmware/lsi/.NOT_RELEASE_DIR
/lib/firmware/lsi/FirmwareID.sh
/lib/firmware/lsi/xrtx_lsifw.sh
/usr/share/man/man8/xrtx_lsifw.8.gz
[root@localhost release]# 



To find out the list of files that an rpm will generate once you install the rpm:
rpm -qlp

[root@localhost tmp]# rpm -qlp /tmp/lsifw-tools-xrtx-1-1.xrtx.1872.src.rpm
lsifw-tools-xrtx-source.spec
lsifw-tools-xrtx.tgz
[root@localhost tmp]#


HTH
Kongkon

Monday, June 18, 2012

C++ Library Problem

Google+

C++ Library Problem

You have a library provided by the vendor. All you have is header files and library files. Library contains the class "Shape" and there is whole hierarchy tree (I mean classes which derive from this base class).

Now you want to add some function "getArea" (not originally present in the class or any of its derived class) in the class "Shape" , you don't have the source code.
Using this library, you have written a lot of code. Now, you have to make some changes so that, any object of "Shape" class (or its derived class) will be able to call this function.

With your strategy, you should be able to override the definition of this function in the derived class.

http://www.careercup.com/question?id=13872673