File: linuxapminfo.pl

package info (click to toggle)
netmrg 0.18.2-14
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,104 kB
  • ctags: 1,575
  • sloc: xml: 8,912; php: 7,389; sh: 4,019; cpp: 2,581; perl: 471; ansic: 338; makefile: 316; sql: 5
file content (56 lines) | stat: -rwxr-xr-x 921 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl
#
# linuxapminfo.pl
#
# reports values of certain apm values
#

use strict;

if (scalar(@ARGV) != 1 
	|| ($ARGV[0] ne "-p" && $ARGV[0] ne "-t")
	)
{
	print "U\n";
	print "\n";
	print "$0 [-p] [-t]\n";
	print "  -p: Report Percent Left\n";
	print "  -t: Report Time Remaining (in minutes)\n";
	print "\n";
	exit(1);
} # end if not enough parameters

# read in info from apm
open 'apmfh', "/proc/apm";
my $apmline = <apmfh>;
close 'apmfh';

## get the value we want
# percent left
if ($ARGV[0] eq "-p")
{
	if ($apmline =~ /(\d+)%/)
	{
		print "$1\n";
		exit(0);
	} # end if found percent left
} # end if percent left to check

# time remaining
elsif ($ARGV[0] eq "-t")
{
	if ($apmline =~ /(\d+)\s+min$/)
	{
		print "$1\n";
		exit(0);
	} # end if found min left
	elsif ($apmline =~ /(\w+)\s+\?$/)
	{
		print "U\n";
		exit(0);
	} # end if indef minutes left
} # end if time remaining

print "U\n";
exit (1);