Debian Codegraph @

connect-stat.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # connect-stat.sh
3 # Note that this script may need modification
4 #+ to work with a wireless connection.
5
6 PROCNAME=pppd # ppp daemon
7 PROCFILENAME=status # Where to look.
8 NOTCONNECTED=85
9 INTERVAL=2 # Update every 2 seconds.
10
11 pidno=$( psscip-shell system . . ps. ax | grepscip-shell system . . grep. -v "ps ax" | grepscip-shell system . . grep. -v grep | grepscip-shell system . . grep. $PROCNAME |
12 awkscip-shell system . . awk. '{ print $1 }' )
13
14 # Finding the process number of 'pppd', the 'ppp daemon'.
15 # Have to filter out the process lines generated by the search itself.
16 #
17 # However, as Oleg Philon points out,
18 #+ this could have been considerably simplified by using "pidof".
19 # pidno=$( pidof $PROCNAME )
20 #
21 # Moral of the story:
22 #+ When a command sequence gets too complex, look for a shortcut.
23
24
25 if [scip-shell system . . `[`. -z "$pidno" ] # If no pid, then process is not running.
26 then
27 echoscip-shell system . . echo. "Not connected."
28 # exit $NOTCONNECTED
29 else
30 echoscip-shell system . . echo. "Connected."; echoscip-shell system . . echo.
31 fi
32
33 while [scip-shell system . . `[`. true ] # Endless loop, script can be improved here.
34 do
35
36 if [scip-shell system . . `[`. ! -e "/proc/$pidno/$PROCFILENAME" ]
37 # While process running, then "status" file exists.
38 then
39 echoscip-shell system . . echo. "Disconnected."
40 # exit $NOTCONNECTED
41 fi
42
43 netstat -s | grepscip-shell system . . grep. "packets received" # Get some connect statistics.
44 netstat -s | grepscip-shell system . . grep. "packets delivered"
45
46
47 sleepscip-shell system . . sleep. $INTERVAL
48 echoscip-shell system . . echo.; echoscip-shell system . . echo.
49
50 done
51
52 exit 0
53
54 # As it stands, this script must be terminated with a Control-C.
55
56 # Exercises:
57 # ---------
58 # Improve the script so it exits on a "q" keystroke.
59 # Make the script more user-friendly in other ways.
60 # Fix the script to work with wireless/DSL connections.