poff 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/sh
  2. # $Id: poff,v 1.1 2002/11/24 23:30:44 etbe Exp $
  3. # Written by John Hasler <john@dhh.gt.org> and based on work
  4. # by Phil Hands <phil@hands.com>. Distributed under the GNU GPL
  5. if [ -x /usr/bin/kill ]; then
  6. KILL="/usr/bin/kill"
  7. else
  8. KILL="/bin/kill"
  9. fi
  10. SIG=TERM
  11. DONE="stopped"
  12. MODE=""
  13. usage ()
  14. {
  15. cat <<!EOF!
  16. usage: $0 [option] [provider]
  17. options:
  18. -r Cause pppd to drop the line and redial.
  19. -d Toggle the state of pppd's debug option.
  20. -c Cause pppd to renegotiate compression.
  21. -a Stop all pppd's. 'provider' will be ignored.
  22. -h Print this help summary and exit.
  23. -v Print version and exit.
  24. none Stop pppd.
  25. Options may not be combined.
  26. If 'provider' is omitted pppd will be stopped or signalled if and only if
  27. there is exactly one running unless the '-a' option was given. If
  28. 'provider' is supplied the pppd controlling the connection to that
  29. provider will be stopped or signalled.
  30. !EOF!
  31. }
  32. # Get option. If there are none replace the "?" that getopts puts in
  33. # FLAG on error with "null".
  34. getopts rdcavh FLAG
  35. if [ "$?" -ne 0 ]; then
  36. FLAG="null"
  37. fi
  38. # Check for additional options. Should be none.
  39. getopts :rdcavh DUMMY
  40. if [ "$?" -eq 0 ]; then
  41. echo "$0: Illegal option -- ${OPTARG}."
  42. exit 1
  43. fi
  44. case $FLAG in
  45. "r") SIG=HUP; DONE=signalled; shift ;;
  46. "d") SIG=USR1; DONE=signalled; shift ;;
  47. "c") SIG=USR2; DONE=signalled; shift ;;
  48. "a") MODE="all"; shift ;;
  49. "v") echo "$0$Revision: 1.1 $_TrickToPrint_RCS_Revision"; exit 0 ;;
  50. "h") usage; exit 0 ;;
  51. "?") exit 1;
  52. esac
  53. # Get the PIDs of all the pppds running. Could also get these from
  54. # /var/run, but pppd doesn't create .pid files until ppp is up.
  55. PIDS=`pidof pppd`
  56. # poff is pointless if pppd isn't running.
  57. if test -z "$PIDS"; then
  58. echo "$0: No pppd is running. None ${DONE}."
  59. exit 1
  60. fi
  61. # Find out how many pppd's are running.
  62. N=`echo "$PIDS" | wc -w`
  63. # If there are no arguments we can't do anything if there is more than one
  64. # pppd running.
  65. if test "$#" -eq 0 -a "$N" -gt 1 -a $FLAG != "a" ; then
  66. echo "$0: More than one pppd running and no "-a" option and
  67. no arguments supplied. Nothing ${DONE}."
  68. exit 1
  69. fi
  70. # If either there are no arguments or '-a' was specified kill all the
  71. # pppd's.
  72. if test "$#" -eq 0 -o "$MODE" = "all" ; then
  73. $KILL -$SIG $PIDS || {
  74. echo "$0: $KILL failed. None ${DONE}."
  75. exit 1
  76. }
  77. exit 0
  78. fi
  79. # There is an argument, so kill the pppd started on that provider.
  80. PID=`ps axw | grep "[ /]pppd call $1" | awk '{print $1}'`
  81. if test -n "$PID" ; then
  82. $KILL -$SIG $PID || {
  83. echo "$0: $KILL failed. None ${DONE}."
  84. exit 1
  85. }
  86. else
  87. echo "$0: I could not find a pppd process for provider '$1'. None ${DONE}."
  88. exit 1
  89. fi
  90. exit 0