#! /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;