Hey monks,

I'm still working on this ssh script. I can get my script to work, but when the firewall dameon is not running and I give the command to bring down the interface ($cmd2)on the other computer, perl just hangs there. Is there a way to break out of the ssh shell after bringing the interfaces down? Also, once I break out of the ssh shell, I want to run some commands on the local machine such as: ifconfig eth0 up and fwstart. How should I incorporate these commands into my script? I would rather not use Net::SSH or Net::SSH::Perl

Thanks for the help,
Dru

#!/usr/bin/perl -w my $result; my $sshprog="/usr/bin/ssh"; my $sshhost="192.168.2.3"; my $sshuser="root"; my $cmd1="ps -ef | grep -v grep |grep fwd"; my $cmd2="ifconfig eth0 down"; $result=`$sshprog $sshuser\@$sshhost $cmd1 2>&1`; if ($? == 0) { print "Firewall Dameon is running\n"; exit 0 } # end if ($? != 0) if ($? != 0) { print "Firewall Dameon is not running. Bringing down the interfaces\ +n"; $result=`$sshprog $sshuser\@$sshhost\ $cmd2 2>&1`; exit 0 } # end if ($result != 0)

 


In reply to Can't Break Out of SSH Shell by dru145

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.