#!/usr/bin/perl -w # vim: set sw=4 ts=4 si et: # Copyright: GPL # Written by Guido Socher # This script must have chmod 6755 and the file should be owned by root # It is a Set-UID script. Therefore you don't need to be logged in a root # to stop the ppp connection. # # use strict; use vars qw($opt_h); use Getopt::Std; # # delete the environment: %ENV=(); # $ENV{'IFS'}=" "; # path must contain the programs kill and killall $ENV{'PATH'}="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin"; $ENV{'HOME'}="/tmp"; $<=$>; &getopts("h")||die "ERROR: No such option. -h for help\n"; &help if ($opt_h); my $i; if ($ARGV[0]){ if ($ARGV[0]=~/^([\w\.:]+)$/){ $i=$1; }else{ die "ERROR: $ARGV[0], not a valid interface name\n"; } }else{ $i="ppp0"; } if (-f "/var/run/$i.pid" ){ print `kill -INT \`cat /var/run/$i.pid\``; if ($?){ # it did not work. Force kill print "Warning: kill -INT failed. Force kill of all pppd processes.\n"; print `killall -KILL pppd`; unlink("/var/run/$i.pid","/var/lock/LCK..modem"); exit 1; } }else{ print "ERROR: ppp-off, link not active, no /var/run/$i.pid file\n"; } # sub help{ print "Stop the ppp connection. USAGE: ppp-off [interface] The default interface is ppp0\n"; exit; } __END__