Wednesday, 28 March 2012

Read a File line by line in a shell script

It is easy to read a file in a bash shell script using while loop.


FileName='example.txt'
while read LINE
do
  echo $LINE
done < $FileName

Check the process id of a running bash shell script

Suppose you have a script named XYZ.sh.


Inside this script you want to make sure that you run this script only if the same script is not already running. Here is how you can do this in bash shell:


# find own PID using $$
echo "My proces id is : $$" 

# find list of PID with process name/parameter as XYZ.sh, and remove grep's PID, own PID
prev_pid=`ps -ef | grep  XYZ .sh |grep -v grep | grep -v $$ | awk '{ print $2 }'`
if [[ $prev_pid != "" ]];then
        echo "    Script is already running with PID: [$prev_pid], so quitting now."
        exit 1;
fi;


Important: This method works only when the script is started as "sh XYZ.sh" and doesn't work if you start it as "./XYZ.sh"

Saturday, 24 March 2012

A billion dollar chat site

Recently i heard about Tencent, a chinese online company which has ~ 700 million user base with $1 billion worth. The online space continues to fascinate me all the more :)

Source:
http://blogs.hbr.org/events/2012/03/where-to-win-in-emerging-marke.html?awid=7554679157562799809-3271 

Thursday, 22 March 2012

Topsy

TOPSY

The search engine giving a new dimension to the search problem.
Topsy is a twitter and feeds based real time search engine.