I have a small problem. It's annoying though. I wrote this shell script:
#
# This script will accept two arguments. The first is a flag and the
# second is a time interval. The only valid flag is '-t' which means
# the user will specify the interval in seconds, otherwise the
# default is 600 seconds. While the interval is counting, the script
# will run the ps command, cut out the process numbers, and
# place them in a temp file. When the interval is met the script
# calls another script which uses the temp file and outputs
# the current time, the number of users logged on, and the
# number of processes run during the interval. It will continually
# loop until the script is killed by ^Z.
while [ 1 -eq 1 ]; do
if test {$1}
then if [ "$1" = "-t" ]
then sleep $2; sh colfile &
let timec=0
while [ timec -le $2 ]
do
ps | cut -f2 -d" " >> proc.tmp
let timec=timec+1
sleep 1
done
else exit
fi
else sleep 5; sh colfile &
let timec=0
while [ timec -le 600 ]
do
ps | cut -f2 -d" " >> proc.tmp
let timec=timec+1
sleep 1
done
fi
done
My problem is that when I run it most of the time it will create multiple instances of itself and I have to individually kill each process. I don't know if it is because I don't have an end to the program and have to press ^Z to stop the program or what it is.
When I typed the command:
sh collect -t 2
After stopping it I did a ps and got this:
PID TTY TIME CMD
29372 pts/4 0:00 sh collect -t 2
33282 pts/4 0:01 -ksh
37414 pts/4 0:00 ps
41604 pts/4 0:00 sh collect -t 2
46194 pts/4 0:00 sh collect -t 2
Notice the 3 instances it created? Does anyone know why it is doing that and how I can stop it or kill the processes right in my script?
Thanks