-1

On linux device, the following process ID runs:

enter image description here

I'm trying to kill the process ids related to ads2 (shown in the image above) remotely (through a bash script that runs on another device). So I tried:

ssh nvidia@"id-address" "kill pgrep ads2"

where pgrep returns the process IDs related to ads2. When i run the script it prompts me to enter the password and then nothing happen, i mean the processes are not terminated.

However, i can't figure out where the error is.

Thanks in advance

Zang322
  • 85
  • 5

1 Answers1

0

kill expects a number (or list of numbers) following it. pgrep ads2 is just words!

For bash to replace the words pgrep ads2 with the result of running that command to produce kill 15951 15995 you can use backticks.

i.e. : kill `pgrep ads2` will first run pgrep ads and then kill (result of pgrep ads2)

However, as you are performing this over ssh, your computer would run the backticks before the remote. I.e. pgrep ads would be run on your local machine, and kill on the remote, which wouldn't work. So you must escape the backticks like so:

ssh nvidia@"id-address" "kill \`pgrep ads2\`"
SamBob
  • 849
  • 6
  • 17
  • Thanlks for the answer. This works for me perfectly. However, it promts me to enter the password for the remote device and i'm wondering if i could pass the password in the script ^ ^ instead of typing it manually? – Zang322 May 10 '21 at 14:27
  • 1
    @Zang322 : As this is a completely different problem, I suggest that you ask a different question - of course after having unsuccessfully googled for _provide password for ssh from script_ or something like this. – user1934428 May 10 '21 at 14:29
  • @user1934428 you're write. Thnaks – Zang322 May 10 '21 at 14:30