简体   繁体   中英

How to pass node name to ssh through pipe in linux command line?

There are several jobs in nodes and want to see my job is running there. Due to the memory problem, the node is occupied by me(user) as sleep (just took the node without actual job) and qstat shows running status but actually no job is running. I need to check using ssh.

qstat shows as follows

  • job-ID prior name user state submit/start at queue slots ja-task-ID
  • 3508392 0.60500 joonho0 joonho r 04/09/2020 12:17:03 skylake@node02 36
  • 3508393 0.60500 joonho1 joonho r 04/09/2020 12:17:03 skylake@node22 36
  • 3509074 0.00000 amplong16 joonho qw 04/09/2020 13:22:20 36

In my trial,

  • qstat | awk '/@/ {print $8}' | cut -d@ -f2

print

  • node02
  • node22

I want to pass these to ssh through pipe then I can use

  • ssh node02 ps aux | grep amp_run.py

where I can check the job "amp_run.py" is running.

But the following fails,

  • qstat | awk '/@/ {print $8}' | cut -d@ -f2 | xargs ssh ps aux | grep amp_run.py

Is there a way to do this in a command line, rather than making a script? Or any other suggestion to check the running jobs in the occupied nodes rather than all nodes?

This was a simple xargs usage. When the arguments which come from pipe locates any place in the next command, -I{} locates the place. So the command should be lime this.

  • qstat | awk '/@/ {print $8}' | cut -d@ -f2 | xargs -I{} ssh {} ps aux | grep amp_run.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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