Bash script help sub process

Associate
Joined
29 Dec 2007
Posts
1,414
Location
London
Hey guys, I'm having slight issues with a script I'm working on. You'll have to forgive my "noobness", I don't do a lot of work with Linux.

I currently run Zabbix as a monitoring server for a few machines, lets say for example a server goes down, it'll pick up on this and send a text message to a primary support phone

I have a secondary support phone, I want the same alert to go there IF primary support hasn't replied to the first alert (via text)

The problem comes in that Zabbix thinks the script has died during the "sleep 300" and retires the script another 2 times, so 3 duplicate messages get sent out.

Script is as follows (I've chopped out 90% of this code to keep it simple):
Code:
#!/bin/sh

#Sends SMS message to primary
echo $TRIGGER $DESCRIPTION | /usr/bin/gammu --sendsms TEXT $NUMBER

#Wait for SMS reply from primary support to disable secondary alerts
sleep 300

#if statement here (reply received?), send message to secondary phone.
echo $TRIGGER $DESCRIPTION | /usr/bin/gammu --sendsms TEXT $secondarynumber

I've tried launching a separate script to do the sleeping like:

sh /blah/blah/secondaryscript.sh

sh (/blah/blah/secondaryscript.sh)&

sh /blah/blah/secondaryscript.sh &

Any other way to have a script launch from within a script but run completely separately?

Thanks :)
 
Last edited:
You can do:

Code:
sh seconday_script.sh &

This will run the secondary_script.sh in the background, however the primary script will then just continue on without waiting.
 
You can do:

Code:
sh seconday_script.sh &

This will run the secondary_script.sh in the background, however the primary script will then just continue on without waiting.

That's what I've tried, I made a typo in the OP :o (corrected now).

It unfortunately doesn't work, it's still tied (somehow) to the host script. Thanks though
 
Last edited:
Just posting to say I didn't realise you could send text messages to a phone from a server. Not surprised in hindsight, but hadn't put two & two together. ZFS drive failed => text is awesome.

You kind of want pthreads, mutex's and so forth. Can't have those in bash though (I assume?). Perl would do it. Otherwise forking a new process would work - I think that's what ChrisB is suggesting, with redirection of stdout and stderr to /dev/null, but I'm struggling to remember how bash works. Too early in the morning.
 
Sorry I thought you wanted to wait for the child processes to terminate, in which case you need nohup
i.e.
nohup myScript.sh &>/dev/null &

This works a treat :D Thank you!

You've made a bunch of secondary support people very happy :)

Just posting to say I didn't realise you could send text messages to a phone from a server. Not surprised in hindsight, but hadn't put two & two together. ZFS drive failed => text is awesome.

You kind of want pthreads, mutex's and so forth. Can't have those in bash though (I assume?). Perl would do it. Otherwise forking a new process would work - I think that's what ChrisB is suggesting, with redirection of stdout and stderr to /dev/null, but I'm struggling to remember how bash works. Too early in the morning.

Yeah we've got a plug in usb modem, basically a 3g dongle. Huawei something or other.
 
Last edited:
Back
Top Bottom