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
4
  • 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. Commented Apr 21, 2020 at 21:03
  • Do you have pgrep on your servers? Commented Apr 21, 2020 at 21:03
  • Have you tried using the ssh -t flag Commented Apr 21, 2020 at 21:26
  • Does this answer your question? bash script execute commands after ssh Commented Apr 21, 2020 at 21:29

1 Answer 1

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}'

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

Comments

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.