bshah has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I'm pretty new to perl. I've written a small sample code which restarts my smtp service. The issue with the below code is, it after it runs /root/scripts/restart.sh on smailhostqa, the control doesn't comes back to Perl. I have to do ctrl-c to exit the script. Since I will be running this from the cron job, I would like to proper exit the script instead of hanging after the command. I thought $ssh->close(); should have closed the ssh session but it didn't.
My question is:
Your help is greatly appreciated.
#! /usr/bin/perl use strict; use Net::SSH::Expect; # Restarting the service.... my $ssh = Net::SSH::Expect->new ( host => "smailhostqa", user => 'root', raw_pty => 1 ); $ssh->run_ssh() or die "SSH process couldn't start: $!" +; $ssh->send("/root/scripts/restart.sh"); print "foo"; $ssh->waitfor('[root\@\w+ ~]#'); $ssh->close();
Janitorial edit: Code tags fixed: Use '</code>', not '<\code>' to close a code tag. Also repaired markup per Writeup Formatting Tips.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl - running remote script doesn't return back the control to perl.
by McA (Priest) on Mar 20, 2014 at 18:43 UTC | |
by bshah (Novice) on Mar 21, 2014 at 16:54 UTC | |
|
Re: Perl - running remote script doesn't return back the control to perl.
by salva (Canon) on Mar 21, 2014 at 09:03 UTC | |
|
Re: Perl - running remote script doesn't return back the control to perl.
by zentara (Cardinal) on Mar 21, 2014 at 09:52 UTC | |
by bshah (Novice) on Mar 21, 2014 at 16:57 UTC |