请帮忙。变量未在Net :: SCP中插值

时间:2013-06-18 07:05:33

标签: perl telnet scp

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

1 个答案:

答案 0 :(得分:0)

那不是真的。如果$found包含值xxx,则字符串文字

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

生成字符串

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

现在,如果$found包含一个可以创建奇数路径的换行符,我不会感到惊讶。也许chomp有序吗?