Shell Scripting - Debugging Shell Scripts
There are various ways of debugging shell scripts, i found these useful when debugging UNIX/LINUX related installer issues.- Add the line set -vx in the beginning of the script. The shell script will then start debug output. You can disable the debug message by adding set +vx from that point onwards debug messages will be disabled
- Or doing sh -x shellscriptfilename (best option out the lot)
- This is similar to the first one except it will be applicable for the complete shell script. By adding
#!/bin/sh -vx
to the beginning of the shell script
Labels: Debugging, Script, Shell Script
Posted by - at 2:36 am | 0 comments read on
Shell Scripting - Monitor Process
This script wil help you in monitoring process resources like memory, cpu usage etc in a portable way across all UNIX/LINUX environment
#!bin/sh
PROCCHECKDELAY=1
RUNCHECKDELAY=2
PROCNORUN=
PAGEROWS=80
PROCNAME=$1
PROCID=
if [ $# -ne 1 ]
then
echo give program name to watch;
exit 1;
fi
stat_process()
{
PROCID=
_mypid=
while [ true ]
do
_mypid=`ps -e 2>/dev/null|grep $1|head -n1|awk '{ print $1 }'`;
if [ ! -z "$_mypid" ]
then
PROCNORUN=
break;
fi
if [ -z "$PROCNORUN" ] ;
then
PROCNORUN=yes
echo "$1 is not running"
echo "recheck after $RUNCHECKDELAY seconds";
sleep $RUNCHECKDELAY;
fi
done
PROCID=$_mypid;
}
i=$PAGEROWS;
while true;
do
stat_process $PROCNAME;
if [ $i -eq $PAGEROWS ] ;
then
i=0;
UNIX95= ps -p $PROCID -o vsz,pid,ruser,rss,pcpu,pmem,args 2>/dev/null
else
UNIX95= ps -p $PROCID -o vsz,pid,ruser,rss,pcpu,pmem,args 2>/dev/null|tail +2
fi
if [ ! -z "$PROCID" ]
then
i=`expr $i + 1`;
fi
sleep $PROCCHECKDELAY;
done;
Labels: CPU Usage, Memory, Process, Shell Script, Unix
Posted by - at 12:37 am | 0 comments read on