このコードは、リモート マシンに 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");