| 1 | #!/bin/bash |
| 2 | # Killing ppp to force a log-off. |
| 3 | # For dialup connection, of course. |
| 4 | |
| 5 | # Script should be run as root user. |
| 6 | |
| 7 | SERPORT=ttyS3 |
| 8 | # Depending on the hardware and even the kernel version, |
| 9 | #+ the modem port on your machine may be different -- |
| 10 | #+ /dev/ttyS1 or /dev/ttyS2. |
| 11 | |
| 12 | |
| 13 | killppp="eval kill -9 `ps ax | awk '/ppp/ { print $1 }'`" |
| 14 | # -------- process ID of ppp ------- |
| 15 | |
| 16 | $killppp # This variable is now a command. |
| 17 | |
| 18 | |
| 19 | # The following operations must be done as root user. |
| 20 | |
| 21 | chmod 666 /dev/$SERPORT # Restore r+w permissions, or else what? |
| 22 | # Since doing a SIGKILL on ppp changed the permissions on the serial port, |
| 23 | #+ we restore permissions to previous state. |
| 24 | |
| 25 | rm /var/lock/LCK..$SERPORT # Remove the serial port lock file. Why? |
| 26 | |
| 27 | exit $? |
| 28 | |
| 29 | # Exercises: |
| 30 | # --------- |
| 31 | # 1) Have script check whether root user is invoking it. |
| 32 | # 2) Do a check on whether the process to be killed |
| 33 | #+ is actually running before attempting to kill it. |
| 34 | # 3) Write an alternate version of this script based on 'fuser': |
| 35 | #+ if [ fuser -s /dev/modem ]; then . . . |