<a href="http://simontekhacks.blogspot.com/2009/04/yeah-more-notes.html#links">http://simontekhacks.blogspot.com/2009/04/yeah-more-notes.html#links</a><br><br>I wrote a how-to on ssh keys. comes in handy. <br><br><div class="gmail_quote">
On Thu, May 10, 2012 at 9:40 AM, Michael H. Warfield <span dir="ltr"><<a href="mailto:mhw@wittsend.com" target="_blank">mhw@wittsend.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Thu, 2012-05-10 at 08:27 -0400, Edward Holcroft wrote:<br>
> This is what worked:<br>
<br>
> $ sshpass -p '1qazxsw2' ssh -o StrictHostKeyChecking=no -t<br>
> <a href="mailto:root@192.168.50.87">root@192.168.50.87</a> "/etc/init.d/asterisk restart; sleep 5; exit"<br>
<br>
</div>The problem you've run into is an old one that been known and discussed<br>
for a long time. What happens is that sshd will not exit until all the<br>
fds are closed, not just that the child has exited. This is intended to<br>
insure that any buffered IO has been passed back to the client before<br>
terminating the server end. What has happened is that your "asterisk<br>
restart" process has forked off a daemon (asterisk service) that has not<br>
closed stdout and stderr so sshd hangs around even though the script is<br>
done. By running the commands the way you did in your "solution", you<br>
run an extra shell to handle the chain of commands with an explicit<br>
exit. There are several different ways of handling it, all with their<br>
pluses and minuses.<br>
<br>
The behavior was discussed over on the OpenSSH forums quite some time<br>
ago and debate invariable boils down to the conclusion - "works by<br>
design - not a bug - will not fix". They blame it on the daemon<br>
processes which did not close out their stdout and stderr fds when they<br>
forked off the daemon process.<br>
<br>
Regards,<br>
Mike<br>
<div class="im"><br>
> On Thu, May 10, 2012 at 7:59 AM, Edward Holcroft <<a href="mailto:eholcroft@mkainc.com">eholcroft@mkainc.com</a>>wrote:<br>
><br>
> > Morning all<br>
> ><br>
> > I need to run a command on an internal server that will restart a given<br>
> > service, in this case asterisk, without user intervention. I using this:<br>
> ><br>
</div>> > sshpass -p '1qazxsw2' ssh -o StrictHostKeyChecking=no <a href="http://root@192.168.50.87/etc/init.d/asterisk" target="_blank">root@192.168.50.87/etc/init.d/asterisk</a> restart<br>
<div class="im">> ><br>
> > The problem is this command never logs out:<br>
> ><br>
> > Stopping safe_asterisk: [ OK ]<br>
> > Shutting down asterisk: [ OK ]<br>
> > Starting asterisk: [ OK ]<br>
> ><br>
> > .... and there it sits, until I manually close it<br>
> ><br>
> > I also tried using -t with the ssh command, which closes the session, but<br>
> > without restarting the service, even though it says it did:<br>
> ><br>
> > $ sshpass -p '1qazxsw2' ssh -o StrictHostKeyChecking=no -t<br>
> > <a href="mailto:root@192.168.50.87">root@192.168.50.87</a> "/etc/init.d/asterisk restart"<br>
> > Stopping safe_asterisk: [FAILED]<br>
> > Shutting down asterisk: [FAILED]<br>
> > Starting asterisk: [ OK ]<br>
> > Connection to 192.168.50.87 closed.<br>
> ><br>
> > I found this article:<br>
> ><br>
> > <a href="http://www.snailbook.com/faq/background-jobs.auto.html" target="_blank">http://www.snailbook.com/faq/background-jobs.auto.html</a><br>
> ><br>
> > And tried:<br>
> ><br>
</div>> > $ sshpass -p '1qazxsw2' ssh -o StrictHostKeyChecking=no <a href="http://root@192.168.50.87/etc/init.d/asterisk" target="_blank">root@192.168.50.87/etc/init.d/asterisk</a> restart < /dev/null<br>
<div class="HOEnZb"><div class="h5">> ><br>
> > which also does not close.<br>
> ><br>
> > Any ideas on how I can get this to run the way I want it to?<br>
> ><br>
> > ed<br>
> > --<br>
> > Edward Holcroft<br>
> > Madsen Kneppers & Associates Inc.<br>
> > 3020 Holcomb Bridge Rd. NW<br>
> > Norcross, GA<br>
> > 30071<br>
> > Tel <a href="tel:%28770%29%20446-9606" value="+17704469606">(770) 446-9606</a><br>
> > GoogleVoice <a href="tel:%28678%29%20587-8649" value="+16785878649">(678) 587-8649</a><br>
> ><br>
> > WARNING/CONFIDENTIALITY NOTICE:This message may be confidential and/or<br>
> > privileged. If you are not the intended recipient, please notify the sender<br>
> > immediately then delete it - you should not copy or use it for any purpose<br>
> > or disclose its content to any other person. Internet communications are<br>
> > not secure. You should scan this message and any attachments for viruses.<br>
> > Any unauthorized use or interception of this e-mail is illegal.<br>
> ><br>
><br>
><br>
><br>
> --<br>
> Edward Holcroft<br>
> Madsen Kneppers & Associates Inc.<br>
> 3020 Holcomb Bridge Rd. NW<br>
> Norcross, GA<br>
> 30071<br>
> Tel <a href="tel:%28770%29%20446-9606" value="+17704469606">(770) 446-9606</a><br>
> GoogleVoice <a href="tel:%28678%29%20587-8649" value="+16785878649">(678) 587-8649</a><br>
><br>
> WARNING/CONFIDENTIALITY NOTICE:This message may be confidential and/or<br>
> privileged. If you are not the intended recipient, please notify the sender<br>
> immediately then delete it - you should not copy or use it for any purpose<br>
> or disclose its content to any other person. Internet communications are<br>
> not secure. You should scan this message and any attachments for viruses.<br>
> Any unauthorized use or interception of this e-mail is illegal.<br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<br>
> Ale mailing list<br>
> <a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
> <a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
> See JOBS, ANNOUNCE and SCHOOLS lists at<br>
> <a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Michael H. Warfield (AI4NB) | <a href="tel:%28770%29%20985-6132" value="+17709856132">(770) 985-6132</a> | mhw@WittsEnd.com<br>
/\/\|=mhw=|\/\/ | <a href="tel:%28678%29%20463-0932" value="+16784630932">(678) 463-0932</a> | <a href="http://www.wittsend.com/mhw/" target="_blank">http://www.wittsend.com/mhw/</a><br>
NIC whois: MHW9 | An optimist believes we live in the best of all<br>
PGP Key: 0x674627FF | possible worlds. A pessimist is sure of it!<br>
</font></span><br>_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>SimonTek<br>912-398-6704<br><br>