Hello fellow monks,
I have a couple of questions in the following code. Basically the code tries to figure out if the user is authorized for SSH without password. So, it forks off a simple command and waits 2 seconds. If it responds within 2 seconds the user is authorized. Otherwise it prints that the user is no longer authorized.
The problem I am having here is after completion of an unauthorized user (where the password prompt is displayed), the terminal no longer works right (pressing enter just redisplays prompt on same line, typing doesnt show up in window etc.) until a 'reset' command is given. What am I missing to either cause the terminal to exit properly, or to reset it (without losing information on the screen) when finished?
A second, less vital question, is how do I keep any text being displayed from the SSH'd term. I have tried saving off STDOUT/STDERR, rdirecting them, and putting them back at the end. This doesn't keep the password prompt from appearing, and doesn't help with messing up the terminal, as I was hoping for 2 birds with one stone.
#! /usr/bin/perl # Libraries use Carp; use strict; use warnings; my $user="MyUserName"; my $host="MyHost.MyDomain.MyCom"; my $pid = 0; #check to see if we are already authorized on system #try to ssh in without password, if finished within #2 seconds, we are authorized, otherwise we are sitting #at password prompt and need to do something eval { local $SIG{'ALRM'} = sub { die "alarm\n" }; $pid = fork; if ($pid) { # Parent alarm 2; waitpid $pid, 0; alarm 0; } else { # Child $SIG{'CHLD'} = 'IGNORE'; #simple command, ignore output just see if runs exec("ssh -f -n -l $user $host uptime"); } }; if ($@) { if ($@ ne "alarm\n") { croak "Unexpected error connecting to '$host'\n"; } kill 9, $pid; print "\nTFD>> <0> Cannot login to '$host'\n"; exit 0; } print "TFD>> <1> Successful login to '$host'\n"; print "done\n"; exit 1;

Note::Why am I not using Net::SSH::Perl? Because Net::SSH::Perl Doesn't seem to work properly on many of my test systems (For example, it stalls for minutes per command on my Fedora Core 6 based machines. This is unusable for something done every 5 seconds.) Creating authorized_keys would allow my test programs to SSH without password, which allows them to perform SSH commands without using faulty Net::SSH::Perl module

Thanks!

s&&VALKYRIE &&& print $_^q|!4 =+;' *|

In reply to SSH leaving terminal confused issue by wulvrine

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.