system returns shell exit status ----- Original Message ----- From: "Mark-Nathaniel Weisman" <[EMAIL PROTECTED]> To: "perl" <[EMAIL PROTECTED]> Sent: Sunday, December 08, 2002 3:23 AM Subject: RE: Using ssh for uptime?
> This is the line that allowed me to capture a uptime value with Perl > using ssh to the remote boxes. > $uptime = system "ssh -l $user $host uptime $pass"; > > The return value is; > 65280 for all boxes. > > Anyone have any idea why I'm not reading the real uptimes, instead I get > the number above. Am I passing the password correctly, when I do this > manually I get a request for a password, could this be an error number? > > His Faithful Servant, > Rev. Mark-Nathaniel Weisman > > -----Original Message----- > From: Mark Goland [mailto:[EMAIL PROTECTED]] > Sent: Saturday, December 07, 2002 1:21 PM > To: Mark Weisman > Cc: perl > Subject: Re: Using ssh for uptime? > > > why are you printing the comman to a file... this is how I would rewrite > the part that does the command. If you dont want to write it as a shell > command use Socket, or use IO::Socket. > > use FileHandle; > use IPC::Open2; > My (@machines,$host,$user,$pass) > > # read your record > Open(INFILE,"<machines.txt") || die "Error opening > machines.txt.$!,stopped" chomp ( @machines = <INFILE> ); Close(INFILE); > > Foreach my $rec (@machines) { > ($host,$user,$pass) = split(/,/, $rec); > open2(*RD_HD, *WR_FH, "ssh $user\@$host uptime") || die cant fork a > child; > <RD_FH>; > > if( m/password/ ){ > print WR_FH "$pass\n"; > > print "\t\t\tHOST $host responded with\n"; > print > "__________________________________________________________\n"; > while (<RD_FH>){print}; > > } > else{ > print "error msg from ssh: $_\n"; > } > > > > } > exit 0; > > this code is untested for more info see perldoc perlipc > > > > # 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); > > #}; > > > > > > > > > > > ##!/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] > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]