From: Ron S. <gee...@ya...> - 2009-04-02 13:20:55
|
The foolowing script is meant to ssh into another machine, check a running script and, if it's not running, start it. I'm stuck at 'Expect->spawn()'. I get: DB<3> p $command Expect=GLOB(0x9a7658c) upon debugging. I'm lost at this point. Any help would be appreciated. #!/usr/bin/perl use warnings; use strict; use Net::SSH::Perl; use Expect; my $host = "someHost"; my $sshConn = Net::SSH::Perl->new($host, port => 22); $sshConn->login("someUser", "somePassword"); chomp (my $cmd = 'ps -ef | grep someProcess | grep -v grep'); my ($out, $err) = $sshConn->cmd($cmd || "ls -l"); if (!defined $out) { print "\n'someProcess' is DOWN and not running. A restart will be attempted.\n\n"; my $command = Expect->spawn("sudo -u root /usr/local/bin/someProgram") or die "Couldn't start program: $!\n"; sleep 2; print $command "somePassword\r"; $DB::single=2; } else { print "\n'someProcess' is UP and running.\n\n"; } $sshConn->cmd("exit"); Ron Smith gee...@ya... (213)300-9448 |