From: Ron S. <gee...@ya...> - 2009-04-02 17:39:47
|
Yes, The following was my effort in that direction, but whent the script is called, a password is required. And, that's the stumbling block for me at that point. I need help to finish it off. :) #!usr/bin perl use warnings; use strict; use Expect; my $ps_check = `ps -ef | grep someScript.sh | grep -v grep`; if ($ps_check) { print "\n'someScript.sh' is running.\n\n"; } else { print "\n'someScript.sh' is not running. An attempt wil be made to start it.\n\n"; my $pid = fork(); if (!defined $pid) { die "Could not fork: $!\n"; } elsif ($pid == 0) { exec("/path/to/someScript.sh"); my $command = Expect->spawn("sudo -u root /path/to/someScript.sh") or die "Couldn't start program: $!\n"; sleep 2; print $command "somePassword\r"; exit; } else { waitpid($pid, 0); } } Ron Smith gee...@ya... (213)300-9448 --- On Thu, 4/2/09, Roland Giersig <rgi...@cp...> wrote: > From: Roland Giersig <rgi...@cp...> > Subject: Re: [Expectperl-discuss] Almost there, but missing something > To: gee...@ya... > Cc: exp...@li... > Date: Thursday, April 2, 2009, 7:58 AM > No need to fiddle with Expect, just create a check-script on > the remote side that does the auto-start and call that with > 'ssh remote-host check-script.sh'. > > HTH, Roland > > Ron Smith wrote: > > 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 > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > > Expectperl-discuss mailing list > > Exp...@li... > > > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > |