return to first page linux journal archive
keywordscontents

Figure 6. The Remote-slirp-off Script

#!/bin/sh
#
## remote-slirp-off -- turn off remote SLiRP and hangup modem

# this script expects a modem to be on both stdin and stdout,
# e.g. `remote-slirp-off </dev/modem >/dev/modem

# exit status
sts=0

# help function
function prthlp()
{
echo ""
echo "usage: $0 [-v]"
echo ""
echo "exit remote SLiRP and hangup modem. we expect the modem not to be"
echo "locked, and we expect our standard input and standard output to be"
echo "connected to the modem. E.g.:"
echo ""
echo " $0 </dev/modem >/dev/modem"
echo ""
echo "options:"
echo "-v verbose operation; logs chat to system log."
echo ""
}

# option defaults
# not blank => verbose chat operation
opt_vrbopr=""

# various options
for i in $*; do
case $i in
-v | --verbose)
opt_vrbopr="-v"
shift
;;
-h | --help)
prthlp
exit 0
;;
*) break
;;
esac
done

function sndxitcmd()
{
chat $opt_vrbopr \
TIMEOUT 1 \
"" 0\\d\\c \
"" 0\\d\\c \
"" 0\\d\\c \
"" 0\\d\\c \
"" 0\\d\\c
return
}

function hupmdm()
{
chat $opt_vrbopr \
TIMEOUT 10 \
"" \\p+\\p+\\p+\\c \
OK ath0 \
OK ""
return
}

# send SLiRP exit signal
echo -n "exiting remote SLiRP ... " 1>&2
if sndxitcmd ; then
echo "done." 1>&2

# hangup modem
echo -n "hanging up modem ... " 1>&2
if hupmdm ; then
echo "done." 1>&2
else
echo -e "\nerror: could not hang up modem." 1>&2
sts=1
fi
else
echo "\nerror: could not send exit command." 1>&2
sts=1
fi

exit $sts


Back to article