简体   繁体   English

与PowerShell命令PLINK不起作用

[英]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. 我有一堆Linux服务器,需要在其中运行一些命令来获取备份服务器的主机文件条目。 I am using planning to make power shell script using plink to achieve this . 我正在计划使用plink制作Power Shell脚本来实现此目的。 It logs me in the server but the commands does not execute. 它将我记录在服务器中,但命令未执行。 Below is Powershell console 下面是Powershell控制台

$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 : 我的c:\\ scripts \\ cmd.txt包含以下两个命令:

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 . 同样,如果有人可以建议一种更好的方法来远程从linux服务器获取输出,那将是很大的帮助。 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. 在所有情况下,如果有99.999%的计算机告诉您找不到东西,则原因是实际上没有东西。 So, are you 100% sure that those commands exist on your server? 那么,您是否100%确定服务器上存在这些命令?

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 ? 您是否100%确定这些命令在root的$PATH

I made a script wich does the same (connect to UNIX machine and execute command using Powershell) and I had to make this: 我做了一个脚本,它执行相同的操作(连接到UNIX计算机并使用Powershell执行命令),我必须这样做:

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

Where $commands are: $ command在哪里:

/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. 因为sudo和userdel并不总是位于mi $ PATH中(如JörgW Mittag所说),所以我必须使用命令的完整路径。

Hope this works for you! 希望这对您有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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