Viki@Stag has asked for the wisdom of the Perl Monks concerning the following question:
When I execute above script it does not come past the first#!/usr/local/bin/perl use strict; if (@ARGV < 2) { usage(); } open (OUT, ">out.log") or die "out.log: $!\n"; select((select(OUT), $|=1)[0]); open (ERR, ">err.log") or die "err.log: $!\n"; select((select(ERR), $|=1)[0]); my $username = 'abc'; # username my $password = 'abc'; # password my $host = shift @ARGV; my @commands_to_run = @ARGV; use IPC::Run qw( start pump finish timeout ); my @startup = ('rlogin', $host, '-l', $username,); my ($in, $out, $err, $h) = (); my $h = start \@startup, \$in, \$out, \$err; $h->pump until ($out =~ /password:/i); $in = "$password\n"; $h->pump until ($out =~ /\[.+\]/); print "Logged into $host as $username\n"; print "Running commands:\n"; foreach my $cmd (@commands_to_run) { print "\t$cmd\n"; print OUT "STDOUT of $cmd ->\n"; print ERR "STDERR of $cmd ->\n"; $in = "$cmd\n"; do { $h->pump; print OUT "$out\n"; print ERR "$err\n"; } until ($out =~ m!\[.+\]!); print OUT "\n\n"; print ERR "\n\n"; } $in = "exit\n"; close OUT; close ERR; print "Loged Out\nDone!\n"; sub usage { print "perl $0 <hostname> <list of commands to run>\n"; print "Example:\n"; die "\tperl $0 host-name "cat /etc/crontab" "cat /path/to/file"\n +"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question on IPC::Run
by zentara (Cardinal) on Mar 09, 2009 at 11:14 UTC | |
|
Re: Question on IPC::Run
by Anonymous Monk on Mar 09, 2009 at 07:40 UTC |