[asterisk-users] How to launch batch whenever Asterisk (re)start ?
Torbjörn Abrahamsson
torbjorn.abrahamsson at gmail.com
Thu Oct 16 13:15:14 CDT 2008
Olivier wrote:
> 2008/10/16 Torbjörn Abrahamsson <torbjorn.abrahamsson at gmail.com>
>
>> You could use #exec statements in one of your config-files.
>
>
> Could you elaborate ?
> Which of /etc/asterisk files are thinking of ?
>
You can put it in any of the files, as far as I know. sip.conf may be a
good place, as you are doing stuff that is SIP related. Add this at the
end of your sip.conf:
------------------
#exec /tmp/do-on-restart.sh
------------------
and enter this in /tmp/do-on-restart.sh:
------------------
#!/bin/sh
UPTIME_TEST=`asterisk -rx 'show uptime' | grep -a "System" | sed -u -e
"s/.*uptime: [0-9] second.*//" -e "s/^ *//" -e "s/ *$//"`
if [ "$UPTIME_TEST" = "" ]; then
# DO STUFF HERE
fi
------------------
Make it executable:
chmod a+x /tmp/do-on-restart.sh
Then restart asterisk and your skript will be run. On my, quite limited,
tests this worked as it should, although it will do the stuff if
asterisk has been running for less than 10 seconds, so if you issue a
reload just after restarting the script will run again... But if this is
an issue you can probably find a way to tweak it.
Of course there may be a better way to get the uptime, but not that I
know of at the moment... Another disclaimer is that this is tested on a
1.2-system, not a 1.4. So I'm not sure if the output of "show uptime" is
the same, maybe it is not called "show uptime", rather "core show
uptime"... But these things should not be that tough to tweak..
Hope you get it to work.
// T
>
>> This would
>> mean that they would be run on every reload. As you asked about running
>> at every restart, not reload, you would have to check if it is indeed a
>> restart. This could possibly be done by checking the uptime with
>> "asterisk -rx 'show uptime'", and then parse this to see if it is quite
>> low, meaning it would be a restart...
>>
>> // T
>>
>>
>>
>> Olivier wrote:
>>> Hi,
>>>
>>> Using Asterisk 1.4, I would like to send a couple of SIP notifies or
>> various
>>> scripts whenever Asterisk restart.
>>> My concern is also deal with restart from CLI but I don't how Asterisk is
>>> restarted when using CLI.
>>>
>>> Is safe_asterisk used ?
>>> What is the best way to do ?
>>>
>>> Regards
>>>
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>>>
>>> asterisk-users mailing list
>>> To UNSUBSCRIBE or update options visit:
>>> http://lists.digium.com/mailman/listinfo/asterisk-users
>> _______________________________________________
>> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>>
>> asterisk-users mailing list
>> To UNSUBSCRIBE or update options visit:
>> http://lists.digium.com/mailman/listinfo/asterisk-users
>>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-users
More information about the asterisk-users
mailing list