Auslesen des Akku-Ladestatus unter Ubuntu
Verfasst von webmaster am So, 12/27/2009 - 17:30
Das folgende Perl-Skript zeigt den prozentuellen Ladezustand einer Netbook-Baterie unter Ubuntu an:
#!/usr/bin/perl $FILE; $fileInfo = "/proc/acpi/battery/BAT0/info"; $fileState = "/proc/acpi/battery/BAT0/state"; $designCapacity=0; $capacity=0; #open info file open( FILE, "< $fileInfo" ) or die "Can't open $fileInfo : $!"; while( <FILE> ) { if ( $_ =~ /^design capacity:s*(d*)s*mAh$/ ) { $designCapacity = $1; } } close( FILE ); #open state file open( FILE, "< $fileState" ) or die "Can't open $fileState : $!"; while( <FILE> ) { if ( $_ =~ /^remaining capacity:s*(d*)s*mAh$/ ) { $capacity = $1; } } close( FILE ); #check data if (($capacity == 0) || ($designCapacity == 0)) { die "Fehler beim Lesen des Batteriestatus"; } #calculate percantge $batterieState = $capacity / $designCapacity * 100; #print state printf("Batterie Status: %3.0f%n", $batterieState );



|