#!/bin/bash NameMod=ttyS1 # NameMod=modem # SpeedMod=38400 SpeedMod=57600 IdleConn=120 WaitConn=40 PPPTeleph=(61999 92259 91263 67235 99262 96786 90982 90420 90832 90498 92207 93056 90835 92570 93549) NPPPTeleph=15 NameLog=/var/log/PPP_connect work_time=0 if [ -e "/var/lock/LCK..$NameMod" ] || [ -e "/var/lock/LCK..modem" ]; then exit 1; fi if [ $# != 2 ]; then echo "No enought of parameters. Must be 2."; exit 1; fi try_c=0; pid_PPPD=0 function TrapFunc() { echo 'SIGTERM signal' if [ $work_time != 0 ]; then let work_time=`date +%s`-work_time; echo Time connect = $work_time c >> $NameLog; fi if [ $pid_PPPD != 0 ]; then kill -s TERM $pid_PPPD; fi exit 1; } trap TrapFunc SIGTERM if [ $? = 0 ]; then echo 'Hand sign SIGTERM OK!'; else echo 'Hand sign SIGTERM Filed!'; fi if [ $2 != 0 ]; then echo "param $1 $2" setsid /usr/sbin/pppd -d -detach /dev/$NameMod $SpeedMod idle $IdleConn connect "/etc/ppp/scripts/dialer $1 $2" exit 0; # while [ -e "/var/lock/LCK..$NameMod" ]; do sleep 1; done fi while [ "1" = "1" ]; do setsid /usr/sbin/pppd -d -detach /dev/$NameMod $SpeedMod idle $IdleConn connect "/etc/ppp/scripts/dialer $1 ${PPPTeleph[ $[$try_c%$NPPPTeleph] ]}" & pid_PPPD=${!} sleep 5; echo ""; echo "Wait try $try_c pid $pid_PPPD "; echo ""; ind=$WaitConn while [ -e "/var/lock/LCK..$NameMod" ] && [ ! $ind = 0 ] && [ -z $(/sbin/ifconfig | grep 'ppp0') ]; do sleep 1; let ind=ind-1; done if [ -z $(/sbin/ifconfig | grep 'ppp0') ]; then # if [ -e "/var/lock/LCK..$NameMod" ]; then kill -s TERM `cat /var/lock/LCK..$NameMod`; fi if [ -e "/var/lock/LCK..$NameMod" ]; then kill -s TERM $pid_PPPD; fi pid_PPPD=0; echo ""; echo "Try failed"; echo ""; sleep 1; let try_c=try_c+1; else echo ""; echo Try OK!; echo ""; echo $1 `whoami` : `date "+%d.%m.20%y %H:%M:%S"` >> $NameLog; work_time=`date +%s`; play /etc/ppp/scripts/glasses.wav & /usr/sbin/ntpdate bear.zoo.bt.co.uk & while [ -e "/var/lock/LCK..$NameMod" ]; do sleep 1; done let work_time=`date +%s`-work_time; echo Time connect = $work_time c >> $NameLog; exit 0; fi done # dial 553055