-1

此代码远程登录到远程机器,获取最新目录。然后将最新的文件夹名称存储到一个变量中,然后发生从远程机器到本地机器的 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");
4

1 回答 1

0

这不是真的。如果$found包含 value xxx,则字符串字面量

 "192.168.12.123:/root/vault/$found/latest/movie.mkv"

产生字符串

 192.168.12.123:/root/vault/xxx/latest/movie.mkv

现在,如果$found包含会创建奇怪路径的换行符,我不会感到惊讶。也许achomp是有序的?

于 2013-06-18T07:12:43.343 回答