SearchSearch  Log in to check your private messagesLog in to check your private messages  recent posts Recent Posts
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
stevebc1Offline



Joined: Dec 17, 2005
Posts: 52
Location: East Anglia
Status: Offline
Posted: Mar 16, 2008 - 10:17 AM Reply with quote Back to top
Hi,
I need to call the config edit "Re-Read Config" function from a script, but at present I have been unable to work out how the PHP calls it.

Any chance of some pointers?

Steve
View user's profile Send private message
ianplainOffline
Site Admin


Joined: Jul 05, 2004
Posts: 2772
Location: Bath UK
Status: Offline
Posted: Mar 16, 2008 - 01:59 PM Reply with quote Back to top
Hi Steve

All its doing is a asterisk.reload script,

Code:
// command for switch to read conf files
// commented out for demo
$reset_cmd = "/bin/asterisk.reload";
//chaged for demo


The script is

Code:
#!/usr/bin/perl -w
use Socket;
use IO::Handle;

system("/usr/bin/killall op_server.pl");

socket(SOCK, AF_INET, SOCK_STREAM, getprotobyname('tcp'))
        or die "Cannot create a socket: $!\n";
connect(SOCK, sockaddr_in(5038, inet_aton('127.0.0.1')))
        or die "Cannot connect to the manager port\n";
SOCK->autoflush(1);
$text = "Action: Login\r\n";
$text .= "Username: phpconfig\r\n";
$text .= "Secret: php[onfig\r\n\r\n";
$text .= "Action: Command\r\nCommand: reload\r\n\r\n";
print SOCK $text;
while (<SOCK>) {
        print if not /Message:/ and not /Response:/ and not /END COMMAND/;
        exit 0 if /END COMMAND/
}

exit 0;


so all you need todo is call the asterisk.reload

Hope that helps
[/quote]
View user's profile Send private message
stevebc1Offline



Joined: Dec 17, 2005
Posts: 52
Location: East Anglia
Status: Offline
Posted: Mar 16, 2008 - 04:09 PM Reply with quote Back to top
Cheers its spot on !

I have an issue with my trixbox that incoming sipgate trunks go to a 6 second cut off if my IP address changes.

I had been rebooting to cure the problem but think a reload may be better hence the question.

I have written a script that can be run by CRON periodically and
compare the current IP and old IP if a change is detected it will cause a reload.

Code:

nslookup some_domain.dyndns.org | tail -2 > ip.txt
IP=$(more ip.txt)
OLDIP=$(more oldip.txt)

if [ "$IP" = "$OLDIP" ];
then
echo no change

else

echo changed
/bin/asterisk.reload
more ip.txt > oldip.txt

fi


Steve
View user's profile Send private message
stevebc1Offline



Joined: Dec 17, 2005
Posts: 52
Location: East Anglia
Status: Offline
Posted: Mar 17, 2008 - 08:33 AM Reply with quote Back to top
I posted my script too soon, when I ran it via cron it didn,t work Sad

Only needed some minor tweaks!

Also added a function to send an email notifying the change.

Code:

nslookup some_domain.dyndns.org | tail -2 > ip.txt
IP=$(tail ip.txt)
OLDIP=$(tail oldip.txt)

if [ "$IP" = "$OLDIP" ];
then
echo no change

else

echo changed
/bin/asterisk.reload

#!/bin/bash
# script to send simple email
# email subject
SUBJECT="IP Change notification"
# Email To ?
EMAIL="someone@somewhere.com"
# Email text/message
EMAILMESSAGE="mail.txt"
echo $IP "from" > $EMAILMESSAGE
echo $OLDIP >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
tail ip.txt > oldip.txt

fi


Notes.

1/ this has only been tested by me disconnecting and reconnecting my router. But it did seem to resolve my sipgate issue.

2/ I run this as a cron job every 5 minutes so in theory the issue could be present for up to 5 minutes .

3/ It works for me I can't say if it will work for you, use at your own risk.

Steve
View user's profile Send private message


View previous topic Printable version Log in to check your private messages View next topic

Post new topic   Reply to topic
Forum Rules and Guidelines | About VoIP User | Privacy Policy


All logos and trademarks in this site are property of their respective owner.
Comments and posts are property of the poster, all the rest (c) 2003-2006 VoIP User.

No part of this site may be reproduced without our prior consent.