Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # This script is written by [email protected].
- # Please, see `man 8 chat` for more info and
- # http://tehm.info/modem_AT_command
- # for AT commands description.
- MODEM="cuau0"
- TIMEOUT="30"
- LOCKFILE="/var/spool/lock/LCK..${MODEM}"
- PHONES="/etc/phones"
- LOGGER="/usr/bin/logger -t dial"
- COUNT="20"
- PAUSE="10"
- DIAL="0"
- # Small description for shell running
- echo "Please, see syslog messages for description"
- # Have we got a username?
- if [ -z $1 ]; then
- RESULT="Please, provide a username!";
- EXIT_CODE="1";
- else
- # Get a phone number
- $LOGGER "Getting a phone number of user $1 from file $PHONES"
- NUMBER=`grep -w "$1" $PHONES | awk '{print $2}'`
- if [ x${NUMBER} = x"" ]; then
- RESULT="Can't find such username or it doesn't have a number";
- EXIT_CODE="1";
- else
- $LOGGER "Phone number is $NUMBER";
- # Don't give up for $COUNT times
- while [ $COUNT -gt 0 ] ; do
- # Check lock file
- if [ -f $LOCKFILE ]; then
- PID=`cat "$LOCKFILE" | tr -d ' '`;
- # Whether the process $PID is running?
- RUN=`ps axopid -p $PID | grep -v PID | wc -l`;
- if [ $RUN -eq 0 ]; then
- $LOGGER "Stale lock on $MODEM PID=${PID}... overriding.";
- DIAL="1";
- else
- $LOGGER "It's already locked by pid $PID. Waiting for $PAUSE seconds...";
- fi
- else
- DIAL="1";
- fi
- if [ $DIAL -eq 1 ]; then
- $LOGGER "Making lock file...";
- echo -e "\t$$" > $LOCKFILE;
- # Let's dial
- $LOGGER "Dialing..."
- chat -t $TIMEOUT -e \
- '' ATZ OK-ATZ-OK ATS7=0 OK \
- ATDT"${NUMBER}" 'NO CARRIER' \
- < /dev/${MODEM} 2>&1 > /dev/${MODEM} \
- | grep -v '^$' | $LOGGER
- # Delete lock file
- rm "$LOCKFILE";
- RESULT="Dial has been done!";
- EXIT_CODE="0";
- break;
- fi
- COUNT=$(($COUNT-1));
- sleep $PAUSE;
- if [ $COUNT -eq 0 ]; then
- RESULT="Script has exhausted attempts!";
- EXIT_CODE="1";
- fi
- done
- fi
- fi
- $LOGGER $RESULT;
- exit $EXIT_CODE;
Advertisement
Add Comment
Please, Sign In to add comment