Saturday, June 29, 2013

Script command in linux

Script command is very useful way to record logs of any command fired in shell, it logs anything printed on screen.

Example:
--------

script myfile.txt
Will log all results into the file myfile.txt. This will open a sub-shell and records all information through this session. The script ends when the forked shell exits (user types exit) or when CTRL-D is typed.

Killing child process in Linux

I had requirement to stop one of your stats collection process at 7 AM, the stats collection was running from one .sh file which was running a .sql file to collect stats.so, to kill entire process i had to find child process (here child process is .sql file).

I searched through the internet and found various tricks to do it, but most of them seems to be not supporting in my bash version. it tried it myself ,here is the code which is working for me.


export xpid2=`ps -ef|grep -v grep|grep collect_daily_stats2|awk '{print $2}'`
echo "parent:"$xpid2
export cpid2=`ps -ef|grep -v grep|grep "$xpid2"|awk '{print $2}'|sed -s '1d'`
echo "child:"$cpid2
kill -9 "$cpid2"
echo "daily stats2 stopped"
 mailx -s"Daily stats2 stopped successfully" teradatamanager@cvscaremark.com  < /dev/null
else


any suggestions are welcome.