Forum Moderators: bakedjake

Message Too Old, No Replies

Help with a Shell Script

Conditional argument executing two lines

         

trillianjedi

10:30 am on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm sure someone here can help me with this one.

I need a shell script running on a CRON job checking to see if a file called "reboot" exists, and if so, executes a kill and then calls a daemon to start:-

if [ -f "reboot" ] ; then
echo "killall -9 SomeApp"

I'm not sure how to then put in the second line? In C/C++ I could do something like@=

if [ -f "/path/to/reboot" ] ; then
{
echo "killall -9 SomeApp"
echo "path/to/SomeApp"
}

Is there a similar way in bash?

Thanks,

TJ

mcavic

7:35 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should work --

if [ -f "/path/reboot" ]; then
killall -9 SomeApp
/path/SomeApp &
fi

trillianjedi

7:47 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Great - so the end of an if statement is "fi"?

What does the "&" do?

Thanks!

TJ

mcavic

10:33 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, that's the syntax in sh, ksh, and bash. & executes the program in the background. That way, the cron job will finish while the program keeps running.

If the application does anything important, like sending email or manipulating data, the killall -9 might cause data loss. It would be better to kill it more gracefully, then wait to see if it finished before restarting it.

Oh, and of course, don't forget rm -f /path/reboot