Startup/Shutdown - info and scriptsMy Inspiron 8600 will power up when power is applied if the button is shorted. So I shorted the leads on the button on the Dock and have the laptop power supplied wired to IGN, so that when the key is turned, the laptop will power on.
For shutdown, I use the following Perl scripts..
| • | /etc/acpi/battery.pl This creates a file with the time we went on battery.
Now how is this called by acpi? I modified /etc/acpi/power.sh to call this script right after the includes. #!/usr/bin/perl
warn "On Battery [$ARGV[0]\n";
my $status = `/usr/bin/acpi -Ba`;
#AC Adapter 1: on-line
my $stat_file = '/var/run/battery_status';
if ($status =~m/on-line/i){
warn "On AC\n";
unlink ($stat_file) if (-e $stat_file);
}else{
warn "On Battery\n";
open (FH, ">$stat_file") or die "Couldn't open battery status file [$stat_file] : $!";
print FH time(),"\n";
} |
|
| • | /usr/local/bin/checkpower The second half of getting this to work is the following script which is called from cron every 3 minutes. (Change to suite your tastes.)
So if we are on battery more than $SHUTDOWN_SECS, the next time [b]checkpower[/b] is run, it will issue a hibernate command. #!/usr/bin/perl
use warnings;
$ENV{PATH} = '/sbin:/usr/sbin:/usr/local/bin:/usr/bin:/bin';
my $SHUTDOWN_SECS = 60 * 5; # How long to wait before shutdown
my $file = '/var/run/battery_status';
my $batt_time;
if (-e $file){
open (FH, "<$file") or die "Couldn't read file: $!";
$batt_time = ;
chomp($batt_time);
print "On battery for ",time()-$batt_time," seconds\n";
if (time() - $batt_time > $SHUTDOWN_SECS){
warn "Shutting down...";
unlink($file); # Clean up
warn "Hibernating\n";
system('/usr/local/sbin/hibernate --force');
}else{
print $SHUTDOWN_SECS - (time() - $batt_time), " seconds until shutdown\n";
}
}else{
# "Nothing to do";
} |
|