--- parse_df.pl 2002/07/18 10:23:24 1.7 +++ parse_df.pl 2003/05/13 16:00:53 1.11 @@ -5,13 +5,14 @@ # filesystems in same order always) # # Dobrica Pavlinusic +# http://www.rot13.org/~dpavlin/sysadm.html # # Usage: # -# parse_df.pl "ssh -i ~cricket/.ssh/df host.dom" /mount_point +# parse_df.pl "ssh -i ~cricket/.ssh/df target.host" /mount_point # ssh into remote host and get data for /mount_point # -# parse_df.pl "ssh -i ~cricket/.ssh/df --config" +# parse_df.pl "ssh -i ~cricket/.ssh/df target.host" --config # dump configuration file to stdout # @@ -38,7 +39,12 @@ return if (defined $df); print STDERR " [cache miss] "; } - open(DF,"$ssh df -klP |") || die "$ssh df: $!"; + eval { + local $SIG{ALRM} = sub { die "ssh timeout\n"; }; + alarm 10; # wait for ssh to connect and return first line + open(DF,"$ssh df -klP |") || die "$ssh df: $!"; + }; + print STDERR " read DF eof=",eof(DF); while() { chomp; my ($node,$total,$used,$aval,$use_pcnt,$mount) = split(/\s+/,$_,6); @@ -50,6 +56,7 @@ } } close(DF); + alarm 0; # turn alarm off $cache->set( $ssh, $df, "1 min" ) if ($USE_CACHE); }