【问题标题】:Not able Execute multiple command in remote Machine Using PSEXEC through Perl script无法通过 Perl 脚本使用 PSEXEC 在远程机器中执行多个命令
【发布时间】:2014-10-10 07:56:43
【问题描述】:

我正在尝试使用 psexec 连接到远程机器并执行多个命令,

当我尝试连接到 sieb 服务器管理器并执行一些相关命令时,执行挂起

system("cmd /c c:\\PsExec.exe \\\\$host_name  -u  $user_name  -p \ $pwd  cmd /c \" $command1 && srvrmgr/g enterprise server /u username /p password /e siebel /s siebserver /c \"cmd to execute\"\"");

我正在通过 perl 脚本运行命令,能够运行其他命令,唯一的问题是,我正在尝试连接到服务器管理器并执行一些相关命令

不知道是什么问题

【问题讨论】:

  • 您正在使用系统调用非 perl 相关的 exe。将此字符串打印到屏幕,复制并粘贴到命令行。这将复制脚本的功能并让您检查错误所在。也许其中一个变量不包含您认为的内容。另见perldoc system

标签: perl psexec siebel


【解决方案1】:

你需要调试你的命令的转义:

use 5.012;

my $host_name = 'HOST_NAME';
my $user_name = 'USER_NAME';
my $pwd       = 'PWD';
my $command1  = 'COMMAND1';

my $cmd = "cmd /c c:\\PsExec.exe \\\\$host_name  -u  $user_name  -p \ $pwd  cmd /c \" $command1 && srvrmgr/g enterprise server /u username /p password /e siebel /s siebserver /c \"cmd to execute\"\"";

print $cmd;

输出:

cmd /c c:\PsExec.exe \\HOST_NAME  -u  USER_NAME  -p  PWD  cmd /c " COMMAND1 && srvrmgr/g enterprise server /u username /p password /e siebel /s siebserver /c "cmd to execute""

一些笔记。

  1. 这个反斜杠 \ $pwd 没有做任何事情
  2. 这些双引号"cmd to execute" 可能需要在shell 级别进行转义。

此外,如果您正在构建一个包含双引号的命令,那么使用不同的分隔符来创建您的字符串可能是个好主意。

以下是我将如何修改您的命令

my $cmd = qq{cmd /c c:\\PsExec.exe \\\\$host_name  -u  $user_name  -p  $pwd  cmd /c " $command1 && srvrmgr/g enterprise server /u username /p password /e siebel /s siebserver /c \\"cmd to execute\\""};

【讨论】:

    【解决方案2】:

    我可以看到srvrmgr 命令和/g 参数之间缺少空格

    【讨论】:

      猜你喜欢
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      • 2013-04-10
      相关资源
      最近更新 更多