shutdown after a period of LAN inactivity
I think you first need to define what counts as "inactivity":
- is there a period the box is less likely to be used (say working hours)?
- what services does the box run?
- do regular users only login remotely or locally as well?
- is it OK to still shut down if all, some or specific processes make use of the box?
If you for instance have only remote users you could use the amount of open network connections to determine a shutdown. Silly example:
Code:
#!/bin/sh --
# Unset debugging and exit-on-error after checking it works as advertised.
set -xe
# Get amount of connections.
CONN=`/bin/netstat -ntu 2>/dev/null| grep -c -v LIST 2>/dev/null`
# Check if var has contents, then scrub netstat headers (x2), else just exit.
if [ -n "$CONN" ]; then CONN=$[${CONN}-2]; else exit 1; fi
# If zero connections, initiate shutdown sequence with a 10 minute warning, else do nothing.
case "$CONN" in 0) /sbin/shutdown -h `date --date='+10 minutes' '+%H:%M'`;;
*) ;; esac
exit 0
This cronjob is extendible with checks for which users are logged in, processes running and any other filter you can think of. Still YMMV(VM).