here's my first ever perl program:
I want to make sure that if I'm away from my machine for a while, then this script ssh's to our main server and kills all my processes there. (I keep forgetting to kill them when I go for lunch and they hog vast amounts of cpu and memory).
I've got this far, and 15 minutes after the screensaver activates the killing starts.
#!/usr/bin/perl
my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='ActiveChanged'\"";
open (IN, "$cmd |");
while (<IN>) {
if (m/^\s+boolean true/) {
print "*** Screensaver is active ***\n";
print "*** Sleeping before megadeath....\n";
sleep(15*60);
print "*** killing all jla processes on anvil...\n";
$result = `ssh anvil pkill -u jla`;
print "*** should all be dead\n";
print $result;
} elsif (m/^\s+boolean false/) {
print "*** Screensaver is no longer active ***\n";
}
}
But what I'd like is to wait 15 minutes while monitoring the keyboard. If say, the 'N' key gets pressed (in the terminal the script is running in), then I want to abort the killing and go back to monitoring the screensaver. This will give me an escape route if the screensaver comes on while I'm getting coffee.
Some sort of Bond-style countdown would be nice, too.
Actually even better would be to notice when the screensaver get unlocked, and stop the countdown if so, going back into monitoring mode. Then I don't even have to worry about remembering to press N.