0

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

2 Answers 2

2

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your response . what do you mean by $PATH ?. Yes the commands exists as when i putty to the server directly i can directly work with those commands
0

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!

1 Comment

Thanks for your response . could you please let me know what is $target here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.