Execute ssh via plink on Windows Host with sudo commands

  asterisk, linux, ssh, windows

I’ve Windows and I need access to Asterik (Linux server), via SSH, to execute one command. Now I open Putty, enter IP Server, Port, user and password SSH, execute the sudo command, enter password again and I see the result. I want to automate this. So, I created one script via PLINK:

plink -ssh -no-antispoof [email protected] -pw PASSWORD -t "echo -e PASSWORD | sudo -S asterisk -rx 'sip show peers';

The command to execute is: sudo asterisk -rx "sip show peers".
The result was:

[sudo] password for user: sudo: asterisk: command not found

So, I changed PASSWORD for PASSWORDn for the next script:

plink -ssh -no-antispoof [email protected] -pw PASSWORD -t "echo -e PASSWORDn | sudo -S asterisk -rx sip show peers;"

[sudo] password for user: Sorry, try again.

[sudo] password for user:

sudo: 1 incorrect password attempt

So, I changed for:

plink -ssh -batch [email protected] -pw PASSWORD -m comando.txt

and comando.txt has:

echo -e "PASSWORD" | sudo -S asterisk -rx "sip show peers"

And the result was:

[sudo] password for user: sudo: asterisk: command not found

I need to create the script/bat for automate the command, so, in one click I will see the result vía CMD. The problem is the interactive command (sudo asterisk) that require password. I can’t modify the sudoers file due to company policy.
How can I execute the command with PLINK or other software or solution?

Source: Windows Questions

LEAVE A COMMENT