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 # ----------------------------------------------------------------------------
22 # $FreeBSD: src/share/examples/isdn/contrib/isdnctl,v 1.1.2.1 2001/08/10 14:59:48 obrien Exp $
23 # $DragonFly: src/share/examples/isdn/contrib/isdnctl,v 1.2 2003/06/17 04:36:57 dillon Exp $
28 echo "Usage: $0 [-i interface] [-f /path/to/users.file] [up|down|show]"
59 if [ -z $USERSFILE ]; then
60 USERSFILE=/var/run/isdn.users.$INTERFACE
68 # Does Usersfile exist?
69 if [ ! -f $USERSFILE ]; then
71 if ! /sbin/ifconfig $INTERFACE | grep "^$INTERFACE.*<UP," > /dev/null; then
72 echo "0" > $USERSFILE || exit 1
74 echo "1" > $USERSFILE || exit 1
76 elif [ ! -w $USERSFILE ]; then
77 echo "Error: $USERSFILE not writeable!"
81 if ! /sbin/ifconfig $INTERFACE | grep "^$INTERFACE.*<UP," > /dev/null; then
82 if ! cat $USERSFILE | grep '^0$' > /dev/null ; then
83 echo "Interface down, removing number from file";
90 echo "`cat $USERSFILE` users online"
93 expr `cat $USERSFILE` + 1 > $USERSFILE
94 /sbin/ifconfig $INTERFACE up
95 echo "`cat $USERSFILE` users online"
98 if cat $USERSFILE | grep '^0$' > /dev/null ; then
102 expr `cat $USERSFILE` - 1 > $USERSFILE
103 if cat $USERSFILE | grep '^0$' > /dev/null ; then
104 echo "`cat $USERSFILE` users online, interface down"
105 /sbin/ifconfig $INTERFACE down
108 echo "`cat $USERSFILE` users online"