简体   繁体   English

无法在远程 Linux 主机上执行命令

[英]Unable to execute the command on the remote Linux hosts

I have multiple hosts(more than 20) and need to execute the command but it is not working as expected.我有多个主机(超过 20 个)并且需要执行命令,但它没有按预期工作。 The individual command is working on all the hosts单个命令正在所有主机上运行

ps -ef |grep \`cat/z/y/x|tail -1| awk '{print$30}'\` 

Script:脚本:

for hsts in `cat /a/b/c/hsts.txt`
  do
  ssh ${id}@${hsts} "cat /z/y/x|tail -1" | awk '{print $30}'
  done

the above snippet will give me the process id on all the hosts.上面的代码片段会给我所有主机上的进程 ID。 i want to know which process is running with this process id and i am trying to use the below command, but it is not working out.我想知道哪个进程正在使用此进程 ID 运行,并且我正在尝试使用以下命令,但它没有成功。 Any thoughts what i am missing.任何想法我错过了什么。

ssh ${id}@{hsts} ps -ef |grep "cat/z/y/x/tail -1" |awk '{print $30}'
# above command is not working when i use in the above do loop

I have multiple hosts ( More than 20) and need to execute the command but it is not working as expected.我有多个主机(超过 20 个)并且需要执行命令,但它没有按预期工作。

  1. This snippet of the code runs on multiple hosts and gives me the process id on the host where i am running.这段代码在多个主机上运行,并为我提供了我正在运行的主机上的进程 ID。

for hsts in cat /a/b/c//hsts.txt # hsts.txt file contains all the hosts do ssh ${id}@${hsts} "cat /z/y/x|tail -1" | for hsts in cat /a/b/c//hsts.txt # hsts.txt 文件包含所有主机做 ssh ${id}@${hsts} "cat /z/y/x|tail -1" | awk '{print $30}' done awk '{print $30}' 完成

  1. I need to modify the above command where i need to see the process which is running based on the process id which i am getting from above snippet of the code.我需要修改上面的命令,我需要根据我从上面的代码片段中获得的进程 ID 查看正在运行的进程。

The below snippet runs on individual hosts and it is displaying me the process but if i incorporate the above in the for loop it is not working.下面的代码片段在各个主机上运行,它向我展示了这个过程,但是如果我将上面的代码合并到 for 循环中,它就不起作用。 Appreciate your help on this.感谢您对此的帮助。 ps -ef |grep `cat /z/y/x|tail -1 |awk '{print $30}' ps -ef |grep `cat /z/y/x|tail -1 |awk '{print $30}'

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

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