Vysh
Vysh

Reputation: 45

Not able Execute multiple command in remote Machine Using PSEXEC through Perl script

Im trying to connect to remote machine using psexec and and execute multiple commands,

Execution is hanging when im trying to connect to sieb server manager and execute some related command

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\"\"");

i'm running the command through perl script , able to run other commands, only issue is when ,i'm trying to connect to server manager and execute some related command

Not able to make out what is the issue

Upvotes: 0

Views: 939

Answers (2)

acop
acop

Reputation: 60

I can see that there is space missing between srvrmgr command and /g parameter

Upvotes: 0

Miller
Miller

Reputation: 35208

You need to debug the escaping of your command:

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;

Outputs:

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""

A couple of notes.

  1. This backslash \ $pwd isn't doing anything
  2. These double quotes "cmd to execute" probably need to be escaped on the shell level.

Additionally, if you are constructing a command that contains double quotes, it's probably a good idea to use a different delimiter to make your string.

The following is how I would rework your command

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\\""};

Upvotes: 0

Related Questions