-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh-execute.pl
More file actions
executable file
·28 lines (25 loc) · 824 Bytes
/
Copy pathssh-execute.pl
File metadata and controls
executable file
·28 lines (25 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl
use Expect;
my $ip = $ARGV[0];
my $login = $ARGV[1];
my $password = $ARGV[2];
my $command = $ARGV[3];
my $prompt = $ARGV[4];
my $timeout = 10;
my $aft = new Expect;
$aft->log_file("/tmp/expect_log","w");
$aft->spawn("ssh $login\@$ip") or die "Cannot ssh to the machine \n";
#$aft->raw_pty(0);
##$aft->log_stdout(0);
$aft->expect($timeout,[ qr'\? $', sub { my $fh=shift;$fh->send("yes\n"); exp_continue; } ],
[ 'password: $',sub { my $fh=shift;$fh->send("$password\n");exp_continue;} ],
['-re','\$ $'],
'-re','\> $'
) or die "cannot ssh";
$aft->send("$ARGV[3]\n");
$aft->expect($timeout,[qr'\)$', sub { my $fh=shift;$fh->send("y\n");exp_continue;} ],
['-re','\$ $'],
'-re','\> $');
$aft->send("exit\n");
$aft->do_soft_close();
exit 0