wulvrine has asked for the wisdom of the Perl Monks concerning the following question:
#! /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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SSH leaving terminal confused issue
by sgifford (Prior) on Apr 24, 2007 at 14:34 UTC | |
|
Re: SSH leaving terminal confused issue
by Moron (Curate) on Apr 24, 2007 at 14:32 UTC | |
|
Re: SSH leaving terminal confused issue
by wulvrine (Friar) on Apr 24, 2007 at 15:51 UTC | |
by Moron (Curate) on Apr 24, 2007 at 16:37 UTC | |
by naikonta (Curate) on Apr 24, 2007 at 17:35 UTC | |
by Moron (Curate) on Apr 24, 2007 at 17:49 UTC | |
|
Re: SSH leaving terminal confused issue
by Bro. Doug (Monk) on Apr 25, 2007 at 03:48 UTC | |
|
Re: SSH leaving terminal confused issue
by cengineer (Pilgrim) on Apr 25, 2007 at 15:41 UTC | |
|
Re: SSH leaving terminal confused issue
by wulvrine (Friar) on May 14, 2007 at 15:02 UTC |