#!/bin/bash # #!F:holdconnections # #!P:/usr/local/sbin # #!D:Holds selected connections after a dial-on-demand ISDN connection #!D: to prevent hangup during ssh or telnet sessions #!D: normally started by /etc/ppp/ip-up #!D: Gets masqueraded connections from netstat, looks for selected destination #!D: ports and send a ping to the destination ip address # #!C:Copyright 1999 by Peter Bieringer # #!V:Version 1.01 1999-04-28 # Changes to # 1.01: first published release # Here define delay of check and ping, should be lower than hangup-timeout CKECKDELAY=10 # seconds # Check whether Dial-Up-Interface is online checkonline() { echo -n "Check Dial-Up-Status:" if imontty | grep -q -i "out"; then # Online echo " online" return 0 else # Offline echo " offline" return 1 fi } # Check for established connections, # test against selected ports and # send a ping to destination check4connection() { # get all connections with netstat netstat -M -n | grep ^tcp | while read proto expire srcip dstip srcprt dummy dstprt dummy; do echo " Get: $srcip:$srcprt / $dstip:$dstprt" # Test for ssh or telnet if [ "$dstprt" = "22" -o "$dstprt" = "23" ]; then echo " Selected: $srcip:$srcprt / $dstip:$dstprt" ping -n -c 1 $dstip >/dev/null fi done } # Start echo "Start: $0" while checkonline; do echo " Check" check4connection sleep $CKECKDELAY done