#!/usr/local/bin/perl use SNMP 1.8; require "getopts.pl"; &Getopts('s:'); $DATADIR= ($opt_s eq '') ? "/var/stats/uptime/" : $opt_s; open (C, ">$DATADIR/current") || die "open($DATADIR/current): $!\n"; my $vars = new SNMP::VarList(['system.sysUpTime.0']); while (<>) { ($host, $com) = split; $err = 0; my $sess = new SNMP::Session ( DestHost => $host, Community => $com); if (!defined($sess)) { print STDERR "Error: $error\n"; $err = 1; } else { $t = time; @vars = $sess->get($vars); if ($sess->{ErrorStr} ne '') { print STDERR "Error: ", $sess->{ErrorStr}, "\n"; $err = 1; } } $r = ($err) ? 0 : $vars[0]; if (open (FH, ">>$DATADIR/$host")) { print FH "$t $r\n"; close FH; } else { warn "open($DATADIR/$host): $!\n"; } print C "$host $t $r\n"; } close C; exit 0;