0

I have multiple hosts(more than 20) and need to execute the command but it is not working as expected . 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 . 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 . 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
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Your loop is missing `ps -ef`. Your command at the end is missing the space after `cat`. With all these typos it's hard to tell what you're really doing wrong. – Barmar Apr 21 '20 at 21:03
  • Do you have `pgrep` on your servers? – Barmar Apr 21 '20 at 21:03
  • Have you tried using the `ssh -t` flag – Algo7 Apr 21 '20 at 21:26
  • Does this answer your question? [bash script execute commands after ssh](https://stackoverflow.com/questions/26434604/bash-script-execute-commands-after-ssh) – Algo7 Apr 21 '20 at 21:29

1 Answers1

0

I have multiple hosts ( More than 20) and need to execute the command but it is not working as expected.

  1. This snippet of the code runs on multiple hosts and gives me the process id on the host where i am running .

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" | awk '{print $30}' done

  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.

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 . Appreciate your help on this. ps -ef |grep `cat /z/y/x|tail -1 |awk '{print $30}'