|
Server IP : 192.168.23.10 / Your IP : 216.73.216.47 Web Server : Apache System : Linux echo.premieradvertising.com 5.14.0-362.8.1.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 7 14:54:22 EST 2023 x86_64 User : rrrallyteam ( 1049) PHP Version : 8.1.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF Directory (0755) : /usr/local/../share/libtool/../ruby/../doc/libicu-devel/../perl-Expect/tutorial/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
#!/usr/bin/perl
# Here we are doing this again only this time we'll do it
#without Echoing the password.
$RSH='/usr/bin/ssh';
$host_to_login_to=shift(@ARGV);
use Expect;
print "Enter password: ";
# First we have to initialize STDIN in to an expect object.
$stdin=Expect->exp_init(\*STDIN);
# Now turn off echoing
$stdin->exp_stty('-echo');
# The easy way to do this is:
#$password=<STDIN>;
#chop $password;
# The somewhat harder way is to use $stdin->expect. This would look like:
#
($match_num,$error,$match,$before,$after)=$stdin->expect(undef,"\r");
$password = $before;
# Turn echo back on
$stdin->exp_stty('echo');
# print that newline that wasn't echoed
print "\n";
$rsh=Expect->spawn($RSH,$host_to_login_to);
# Look for a password prompt.
$rsh->expect(30,'-re','word:\s$')||(die"Never got password prompt\n");
print $rsh "$password\r";
# Look for a prompt. Prompt can be # $ > or ] followed by a whitespace.
$prompt = '[\]\$\>\#]\s$';
# Note the use of -re
$rsh->expect(30,'-re',$prompt)||(die "Never got prompt on host\n");
# Start top
print $rsh "exec top\r";
# OK, now return control to user.
$rsh->interact();