4 # Control the ISDN line based on usage
6 # This script can control the state of your ISDN line. It counts
7 # how many scripts/users currently use the ISDN line and uses
8 # "ifconfig down" if noone uses it any more.
9 # I use this script for cronjobs that fetch mail and news and run cvsup.
10 # If I'm still using the line, the script won't close the connection,
11 # but if not, it saves a lot of phone costs.
13 # ----------------------------------------------------------------------------
14 # "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp):
15 # Alexander Langer <alex@big.endian.de> wrote this file. As long as you retain
16 # this notice you can do whatever you want with this stuff. If we meet some
17 # day, and you think this stuff is worth it, you can buy me a beer in return.
20 # ----------------------------------------------------------------------------
27 echo "usage: $0 [-i interface] [-f /path/to/users.file] [up|down|show]"
58 if [ -z $USERSFILE ]; then
59 USERSFILE=/var/run/isdn.users.$INTERFACE
67 # Does Usersfile exist?
68 if [ ! -f $USERSFILE ]; then
70 if ! /sbin/ifconfig $INTERFACE | grep "^$INTERFACE.*<UP," > /dev/null; then
71 echo "0" > $USERSFILE || exit 1
73 echo "1" > $USERSFILE || exit 1
75 elif [ ! -w $USERSFILE ]; then
76 echo "Error: $USERSFILE not writeable!"
80 if ! /sbin/ifconfig $INTERFACE | grep "^$INTERFACE.*<UP," > /dev/null; then
81 if ! cat $USERSFILE | grep '^0$' > /dev/null ; then
82 echo "Interface down, removing number from file";
89 echo "`cat $USERSFILE` users online"
92 expr `cat $USERSFILE` + 1 > $USERSFILE
93 /sbin/ifconfig $INTERFACE up
94 echo "`cat $USERSFILE` users online"
97 if cat $USERSFILE | grep '^0$' > /dev/null ; then
101 expr `cat $USERSFILE` - 1 > $USERSFILE
102 if cat $USERSFILE | grep '^0$' > /dev/null ; then
103 echo "`cat $USERSFILE` users online, interface down"
104 /sbin/ifconfig $INTERFACE down
107 echo "`cat $USERSFILE` users online"