Выход в интернет с двух провайдеров - основной и резервный. Issabel4 PBX за NAT. Решил автоматизировать смену IP при падении основного канала. Подсмотрел в интернете скрипт, засунул в cron и начал тестить. Так вот самая последняя команда и не работает.
Cron:
*/3 * * * * root /var/sh/ip_check/ip_check.sh
Скрипт:
PRIME_BBCODE_SPOILER_SHOW PRIME_BBCODE_SPOILER:
#!/bin/bash
# ip_check.sh
# Description: script that queries checkip.dyndns.com to find the server's external IP address. Updates asterisk's externip value and does a sip reload if necessary.
is_ip(){
input=$1
octet1=$(echo $input | cut -d "." -f1)
octet2=$(echo $input | cut -d "." -f2)
octet3=$(echo $input | cut -d "." -f3)
octet4=$(echo $input | cut -d "." -f4)
stat=1
if [[ $input =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] && [ $octet1 -le 255 ] && [ $octet2 -le 255 ] && [ $octet3 -le 255 ] && [ $octet4 -le 255 ];
then stat=0
fi
return $stat
}
EXTERNIP=`wget -qO- checkip.dyndns.com | awk '{print $6}'| cut -d "<" -f1`
is_ip $EXTERNIP
if [ $? -ne 0 ];
then
logger -s "ip_check.sh: External IP address invalid or unavailable, exiting."
exit 1
fi
OLDEXTERNIP=`grep externip /etc/asterisk/sip_general_additional.conf | cut -d"=" -f2`
echo $OLDEXTERNIP
if [ "$EXTERNIP" = "$OLDEXTERNIP" ]; then
logger -s "ip_check.sh: External IP address "$EXTERNIP" is the same, nothing to do exiting."
exit 0
else
logger -s "ip_check.sh: External IP address has changed "$OLDEXTERNIP" --> "$EXTERNIP", changing /etc/asterisk/sip_general_additional.conf"
grep -v "externip" /etc/asterisk/sip_general_additional.conf > /etc/asterisk/sip_general_additional.conf.tmp
echo "externip=$EXTERNIP" >> /etc/asterisk/sip_general_additional.conf.tmp
cp /etc/asterisk/sip_general_additional.conf.tmp /etc/asterisk/sip_general_additional.conf
rm /etc/asterisk/sip_general_additional.conf.tmp
logger -s "Doing asterisk -rx sip reload"
asterisk -rx "sip reload"
fi
# ip_check.sh
# Description: script that queries checkip.dyndns.com to find the server's external IP address. Updates asterisk's externip value and does a sip reload if necessary.
is_ip(){
input=$1
octet1=$(echo $input | cut -d "." -f1)
octet2=$(echo $input | cut -d "." -f2)
octet3=$(echo $input | cut -d "." -f3)
octet4=$(echo $input | cut -d "." -f4)
stat=1
if [[ $input =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] && [ $octet1 -le 255 ] && [ $octet2 -le 255 ] && [ $octet3 -le 255 ] && [ $octet4 -le 255 ];
then stat=0
fi
return $stat
}
EXTERNIP=`wget -qO- checkip.dyndns.com | awk '{print $6}'| cut -d "<" -f1`
is_ip $EXTERNIP
if [ $? -ne 0 ];
then
logger -s "ip_check.sh: External IP address invalid or unavailable, exiting."
exit 1
fi
OLDEXTERNIP=`grep externip /etc/asterisk/sip_general_additional.conf | cut -d"=" -f2`
echo $OLDEXTERNIP
if [ "$EXTERNIP" = "$OLDEXTERNIP" ]; then
logger -s "ip_check.sh: External IP address "$EXTERNIP" is the same, nothing to do exiting."
exit 0
else
logger -s "ip_check.sh: External IP address has changed "$OLDEXTERNIP" --> "$EXTERNIP", changing /etc/asterisk/sip_general_additional.conf"
grep -v "externip" /etc/asterisk/sip_general_additional.conf > /etc/asterisk/sip_general_additional.conf.tmp
echo "externip=$EXTERNIP" >> /etc/asterisk/sip_general_additional.conf.tmp
cp /etc/asterisk/sip_general_additional.conf.tmp /etc/asterisk/sip_general_additional.conf
rm /etc/asterisk/sip_general_additional.conf.tmp
logger -s "Doing asterisk -rx sip reload"
asterisk -rx "sip reload"
fi
[2024-08-08 11:38:02] VERBOSE[3423] asterisk.c: Remote UNIX connection
[2024-08-08 11:38:02] VERBOSE[3536] chan_sip.c: Reloading SIP
[2024-08-08 11:38:02] VERBOSE[26034] asterisk.c: Remote UNIX connection disconnected
А если отрабатывает скрипт - центральной строчки в логе нет.
Может кто сталкивался с таким? Как понять что не так?