Shutdown Script

Im writing a script to read a file called shutdown.cf and shut down any scripts that are listed there.

I have came up with the following based on things I saw in similar programs but it doesn not work:

Has anybody any idea what I may be doing wrong?

Cheers
Paul


  1. ^0-9 ↩︎

scriptName="$line"

"It doesn not work" means..? do you get undesirable result or any error. I have highlighted some suggestions below

scriptName=""
filename="/var/opt/moto/live/scripts/pwp_access/shutdown.cf"

while read line
do
scriptName="$line" # echo statement not needed
pidNumber=`pgrep -f "$scriptName"`
monproc=`ps -efa | grep "$scriptName" |grep -v 'grep'|sed 's/^[^0-9]*\([0-9]*\)[^0-9].*$/\1/'`
kill -9 $monproc

done < $filename

exit

One more thing..have a echo statement for pidNumber and monproc so that could confirm that you have the right value stored in those variables.

The matching is not very exact, therefore more processes may be matched than intended. Try:

ps -efa | grep " -*$scriptName$" | ....

Got sorted. Cheers guys.