此代码远程登录到远程机器,获取最新目录。然后将最新的文件夹名称存储到一个变量中,然后发生从远程机器到本地机器的 scp。但是 scp 部分不起作用。
#!/usr/bin/perl -w
use Net::Telnet;
use Net::SCP::Expect;
$telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die');
$telnet->open('192.168.12.123');
$telnet->login("liam", "thegrey");
@output = $telnet->waitfor('/\$ $/i');
my @lines=$telnet->cmd('ls');
print"\t\tLOGIN IN SUCESS!!\n\n\n";
$telnet->cmd('cd vault');
print "\t\tThe latest file is >\n";
my @update;
@update=$telnet->cmd(
'ls -l| grep Latest| tail -5 | head -2 | tail -1|tr -s " " | cut -d " " -f9');
my $found=join("",@update);
print "$found"; #The required value is printed here.
my $scpe = Net::SCP::Expect->new(user=>'liam',password=>'thegrey');
#The $found variable is not being interpolated.
$scpe->scp("192.168.12.123:/root/vault/$found/latest/movie.mkv",
"/root/ashesh_assignment/movie.mkv");