【问题标题】:ssh to windows machine and executing a bat filessh 到 windows 机器并执行一个 bat 文件
【发布时间】:2013-08-26 20:30:36
【问题描述】:

我的 .bat 文件位于 windows 中,我想通过 ssh 从 Linux 调用它。我已经在 Windows 中安装了 cygwin,并且可以通过 ssh 连接到机器。我想编写一个 Perl 脚本来连接到 windows 服务器并执行 .bat 文件。

【问题讨论】:

    标签: perl cygwin


    【解决方案1】:

    这种任务的方法是Net::SSH

    例如。 :

    use Net::SSH qw(ssh issh sshopen2 sshopen3);
    
    ssh('user@hostname', $command);
    
    issh('user@hostname', $command);
    
    ssh_cmd('user@hostname', $command);
    ssh_cmd( {
      user => 'user',
      host => 'host.name',
      command => 'command',
      args => [ '-arg1', '-arg2' ],
      stdin_string => "string\n",
    } );
    
    sshopen2('user@hostname', $reader, $writer, $command);
    
    sshopen3('user@hostname', $writer, $reader, $error, $command);
    

    【讨论】:

      【解决方案2】:

      使用以下任何一种:

      • Net::OpenSSH:好用,不支持Windows,但可以连接Windows主机。
      • Net::SSH2:不太好用,随处可用。
      • Net::SSH::Any:上述模块的包装器,具有易于使用的 API。不过,仍然不完整。

      例如:

      use Net::SSH::Any;
      my $ssh = Net::SSH::Any->new($host, user => $user, password => $password);
      my @output = $ssh->capture('c:\foo.bat');
      

      【讨论】:

      • 我厌倦了 Net::SSH::Any,但它会引发以下错误。在 /usr/lib/perl5/site /Net/SSH/Any.pm 第 388 行的连接 (.) 或字符串中使用未初始化的值。(在清理中)转到 /usr/lib/perl5/ 的未定义子例程 &main::DESTROY .8.8/Net/SSH/Any.pm 第 388 行。
      • 您能描述一下您的(本地)环境吗?操作系统、perl 和模块版本?
      猜你喜欢
      • 1970-01-01
      • 2013-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 2018-11-28
      相关资源
      最近更新 更多