简体   繁体   中英

plink with powershell commands not working

I having a bunch of Linux Servers on which i need to run few commands to get the host file entry of backup servers. I am using planning to make power shell script using plink to achieve this . It logs me in the server but the commands does not execute. Below is Powershell console

$switch = "172.20.19.50"
$commands = "c:\scripts\cmd.txt"
$username = root
$pw =  Read-Host -Prompt "Enter password" -AsSecureString
plink -ssh $switch -l $username -pw $pw -m $commands

output

bash: Support: command not found
bash: Maintenance: command not found

my c:\\scripts\\cmd.txt contains following two commands :

Support
Maintenance

is there anything in command i am missing here ? Also if anyone could suggest a better way to get the output from linux servers remotely will be great help . I just need to query few commands to get the output

In 99.999% of all cases, if a computer tells you it cannot find something, the reason is, that that something is, in fact, not there. So, are you 100% sure that those commands exist on your server?

In the remaining cases, the reason is, that the thing is there, but not in the right place. Are you 100% sure that those commands are in root's $PATH ?

I made a script wich does the same (connect to UNIX machine and execute command using Powershell) and I had to make this:

echo y | & $Plinkpath -P 22 -v $User@$server -pw $passw "$commands $($target)"

Where $commands are:

/usr/local/bin/sudo /usr/sbin/userdel

Because sudo and userdel was not always in mi $PATH (as said Jörg W Mittag) i've to use the full path to the command.

Hope this works for you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM