#!/usr/bin/perl # # Laptop SETI Manager - 0.0.5 # # A silly little script to save battery power on laptops running GNU/Linux. # It starts/stops the SETI@home client based on which power # supply the laptop is running off of. When AC power is detected, # setiathome is started, and when AC power is removed (ie. on # battery) setiathome is killed. There are probably better ways # to do this, but it works. :-) # # Laptop SETI Manager is written by Scott Holmes (norgasm@hotmail.com) # This software is provided to the public domain without # any warranty expressed or implied. Use at your own risk. # Feel free to drop me a line if this was useful to you. # # Usage: # Add 'nohup [path]/lapsetiman & > /dev/null' to your rc.local # file to have setiman started on bootup, and forget it's there... # (I hope).... # my $path = '/root/seti'; #Path to SETI@home files my $interval = 30; #Time in seconds between polls use strict; my $apm; my @apm; my $junk1; my $junk2; while (1) { ####################################### # Find the pid of the SETI@home client # by parsing the output of ps my $pid = ''; open (PS, 'ps aux | ') || die "Cannot run ps!\n"; while () { if (/setiathome/i) { s/ +/ /; ($junk1, $pid, $junk2) = split / /; } } close (PS); ####################################### # Look in /proc/apm to determine if # we're on AC power or battery open (APM, '/proc/apm') || die "Cannot open $!: You need to have \/proc filesystem with apm!\n"; my $apm = ; close (APM) || die "Cannot close $!\n"; my @apm = split / /, $apm; ####################################### # Take appropriate action (either start # or stop the SETI@home client). if ($apm[3] eq '0x01') { # print "Power is ON\n"; if ( !$pid ) { chdir $path || die "$! does not exist\n"; system './setiathome &'; } } else { if ($pid) { kill 9, $pid } # print "Power is OFF\n"; } sleep $interval; }