#!/usr/bin/perl $sleepfile = "/var/run/sleep.counter"; $who = `ps auxw | grep sshd: | grep -v grep`; @who = split(/\n/,$who); $wc = @who; exit(0) if(-f "/var/run/stayawake"); if($wc == 0) { open(SLEEP,"<$sleepfile"); $count = ; $count = 0 if(!$count); close(SLEEP); $count++; open(SLEEP,">$sleepfile"); print SLEEP "$count\n"; close(SLEEP); } if($count > 5) { system("/sbin/shutdown -h +3 \"Automatic shutdown of idle system\""); } exit(0);