Mark,

   It may be easier to go by route of the Net::SSH::Perl module or
Net::SSH module


#!/usr/bin/perl
use strict;
use warnings;

my $user = "bob";
my @hosts = "host1, host2, host3, host3";

foreach my $host (@hosts) :
   my $cmd = "/usr/bin/uptime";
   my $ssh = Net::SSH::Perl->new( $host, port => 22 );
      $ssh->login($user);
   my ( $out, $error, $exit ) = $ssh->cmd( $cmd );
   my ( $time, $uptime ) = ( split /\|/, $out[0] )[1,1];
   print "$host has been up $uptime\n";
}


##################
or something along that lines.  The cmd output spits to $out.  You can
do with it what ever you like... I think that should all work..

chad






On Sat, 2002-12-07 at 12:11, Mark Weisman wrote:
> I've got a script that I'm working on that will use SSH to check the
> uptime on servers within my domain. However, I'm unsure of how exactly
> to do this this is what I have so far.
> 
> ##!/usr/bin/perl
> 
> #My (@machines,$host,$user,$pass)
> 
> #Open(INFILE,"<machines.txt")
> #     or die "Error opening machines.txt.$!,stopped"
> #@machines = <INFILE>;
> #Close(INFILE);
> #Foreach my $rec (@machines) {
> #     chomp($rec);
> #     ($host,$user,$pass) = split(/,/, $rec);
> #     open (OUTFILE, ">records.txt")
> #             or die "Error opening records.txt.$!,stopped";
> #     close(OUTFILE);
> #     open (OUTFILE, ">>records.txt")
> #             or die "Error opening records.txt.$!,stopped";
> #     print OUTFILE 'ssh -l $user $host "uptime"';
> #     close(OUTFILE);
> #};
> Without the hash marks of course. Where am I going wrong? Help please?
> 
> His Faithful Servant,
> Mark-Nathaniel Weisman
> President / CEO
> Infinite Visions Educational Systems Inc.
> Anchorage, Alaska
> http://www.ivedsys.com
> [EMAIL PROTECTED]
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to