my($stdout, $stderr, $exit)
所以我试图使用代码将命令行发送到远程服务器,但我不知道我是否正确,这是代码
#!/usr/bin/perl
use warnings;
use Net::SSH::Perl;
use strict;
#my($stdout, $stderr, $exit) = $ssh->cmd("ls -l /home/$usr")
my $host = "$host";
my $usr = "$usr";
my $pwd = "$pwd";
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($usr,$pwd);
$ssh->cmd("script /home/$usr/textput.txt/");
$ssh->cmd("ls -l /$usr/jrivas/");
$ssh->cmd("exit");
当我运行代码时,似乎工作正常,直到我检查它是否在服务器中创建了脚本,但它不是那样,所以我想象的是我发送命令的方式。
更新
我设法连接到我的服务器并生成.txt文件,但我无法将其自动保存到我的外出PC而不是服务器
这是我到目前为止的代码
#!/usr/bin/perl
use Net::SSH2;
use Net::SSH::Expect;
use Net::SSH::Perl;
use Net::SSH;
#my($stdout, $stderr, $exit) = $ssh->cmd("ls -l /home/$usr")
my $host = "host";
my $usr = "root";
my $pwd = "pwd";
#my $ssh = Net::SSH::Perl->new($host);
#$ssh->login($usr,$pwd);
my $ssh = Net::SSH::Expect->new (
host => "$host",
password=> "$pwd",
user => "$usr",
raw_pty => 1
);
my $login_output = $ssh->login();
if ($login_output !~ /Welcome/) {
die "Login has failed. Login output was $login_output";
}
my $script = $ssh->exec("script /home/jrivas/script_output.txt");
my $script = $ssh->exec("ls -l /home/jrivas");
my $script = $ssh->exec("ls -a /home/jrivas");
my($out, $err, $exit) = $ssh->cmd("cat script_output.txt");
my $script = $ssh->exec("exit");
#$ssh->cmd("script /home/jrivas/textputq.txt/");
#$ssh->cmd("ls -l /home/jrivas");
#$ssh->cmd("exit");
接下来就是让script_output.txt自动保存在我的电脑中
感谢@zdim帮助我:)