The output from "systat -ifstat 1" is quite difficult to parse, so you probably want to look at using snmpget then use a "service" script similar to the one I wrote for idle SAS/SCSI disks
here.
Enable SNMP in services, then use "snmpwalk -c public -v 2c localhost ifName" to determine the index (.1, .2) of your ethernet interface.
Then you can get the interface in/out stats using snmpget, eg. if your ethernet interface is index #1, "snmpget -c public -v 2c -Ov localhost ifInOctets.1 ifOutOctets.1".
Poll snmpget periodically, determine the delta between the previous poll and the current poll, and if it's zero for a repeated period of time then you can shutdown your server.
The following example should get you going, though I doubt you'll ever see zero activity on your ethernet interface for any prolonged period due to various heartbeats and other polling activity, in which case you may have to modify the criteria for shutting down the server eg. assume "idle traffic" as being up to, say, 5K/minute in either direction (in or out).
The example below assumes a 10KB in-bound and 2KB out-bound threshold in any particular time period, and would shutdown the server after 10 continuous 60 second periods (ie. 10 minutes) of "idle" or below-threshold traffic.
Code:
#!/bin/sh
#set -xv
TMPFILE=/tmp/ifoctets.dat
SNMP_COMMUNITY=public
SNMP_HOST=localhost
SNMP_INDEX=1
SNMP_GET="/usr/local/bin/snmpget -c $SNMP_COMMUNITY -v 2c -Ov $SNMP_HOST ifInOctets.$SNMP_INDEX ifOutOctets.$SNMP_INDEX"
TIMEOUT=10
TIMEDELAY=60
THRESHOLD_IN=10240
THRESHOLD_OUT=2048
echo "Count In Delta Out Delta"
COUNT=$TIMEOUT
OCT_IN2=0
OCT_OUT2=0
while [ true ]; do
let OCT_IN1=OCT_IN2 >/dev/null
let OCT_OUT1=OCT_OUT2 >/dev/null
$SNMP_GET | tr -s '\n' ' ' > $TMPFILE
read C1 OCT_IN2 C2 OCT_OUT2 < $TMPFILE
let OCT_IN=OCT_IN2-OCT_IN1 >/dev/null
let OCT_OUT=OCT_OUT2-OCT_OUT1 >/dev/null
# if [ ${OCT_IN-0} -le 0 -a ${OCT_OUT-0} -le 0 ]; then
if [ ${OCT_IN-0} -lt $THRESHOLD_IN -a ${OCT_OUT-0} -lt $THRESHOLD_OUT ]; then
let COUNT=COUNT-1 >/dev/null
else
COUNT=${TIMEOUT}
fi
printf " %.3d %11d %11d\n" $COUNT $OCT_IN $OCT_OUT
[ $COUNT -le 0 ] && break || sleep $TIMEDELAY
done
echo "SHUTTING DOWN SERVER"
#shutdown -p now