Modem Hangup (was Re: [TriLUG] Some Newbie Linux Questions)

Jeremy Portzer jeremyp at pobox.com
Wed Jan 1 22:06:05 EST 2003


On Mon, 2002-12-30 at 16:53, al johnson wrote:

> And I also have another which I asked a long time ago when I first joined 
> Trilug. 
> 
> I asked if there was a way to hang up my modem (i.e. my internet connection 
> and telephone) without resetting the computer at any period of time that I 
> might desire, e.g. 10 min. , 20 min., 1 hour, 2 hours, 2 hours and 20 mins., 
> etc. At that time long before I had a good working Linux machine I was given 
> a one line Terminal command to accomplish just that. If anyone remembers what 
> it was, I'd love to have it now!!. 
> ----Thanks A lot everyone. 

Hi Al,

I'm just getting back from vacation so sorry about the late response. 
For this question, are you interested in hanging up the modem after 10
minutes/etc of inactivity, or just after 10 minutes period?  I don't
know of a simple way for hanging after "inactivity" (since sometimes
your computer does things in the background even when you aren't).

But if you just want to make your modem hang up after a certain amount
of time, a simple script could do it.  The command to hang up your modem
is probably "ifdown ppp0"  (if ppp0 is the interface for your modem; it
possibly could be different -- type "ifconfig -a" to see all the network
interfaces configured on your computer.)  So, you'd just want to write a
script to hang up after a certain amount of time.  The following could
work:

----cut here----
#!/bin/sh

# This script will active device ppp0 (assumed to be a dialup modem) and
# connect for the number of minutes specified on the command line.

# This command will active the ppp0 interface and exit the script if 
# activation fails

ifup ppp0  || exit $?

# This command calculates the number of seconds in the number of minutes
# given by the first command-line argument ($1).

SECONDS=`echo 60 * $1 | bc`

# this command pauses for the calculated number of seconds

sleep $SECONDS

# this command hangs up the modem by downing the interface

ifdown ppp0

---end script---

Hope this helps,

Jeremy




More information about the TriLUG mailing list