0

I'm trying to close programs in several different servers basically at once, and each has a separate timeout. I've tried ssh «ServerName» 'sleep 2s; otherCommand', but that sleeps the main terminal I'm running from. I've tried looking it up, and failed at finding anything relevant. The desired behavior is for the server, let's say Server 1, to wait 2s before executing the second command, while the main server I'm running on, let's say Server 2, continues to queue other commands both to it, and to other servers. Currently, Server 2 waits for 2s, then continues sending commands out.

Thanks in advance!

1
  • The remote is doing the sleep. However the local is waiting for the remote to complete (otherCommand). Commented Jul 11, 2018 at 13:00

1 Answer 1

1

The remote is doing the sleep. However the local is waiting for the remote to complete (otherCommand).

Have you tried running it in background?

ssh «ServerName» 'sleep 2s; otherCommand' &

5
  • That is exactly what I was missing. Thank you so much!! Commented Jul 11, 2018 at 13:09
  • It might be preferable to use ssh -f("requests ssh to go to background just before command execution."), especially if password-based authentication is required Commented Jul 11, 2018 at 13:12
  • @steeldriver I agree might, however -f does not allow job control. Commented Jul 11, 2018 at 13:21
  • After some more testing, I realized it isn't quite working how I wanted, and the error was being piped away so I didn't see it. The full command is ssh <<ServerName>> 'sleep 2s; pgrep <<ProcessName>> |xargs kill -9;' &. That throws a syntax error near unexpected token `&', and the process doesn't get killed. I'm wondering what I'm doing wrong there. ProcessName is always and solely the name of the process, and nothing else shares it, so killing from the pgrep isn't my problem The main terminal is no longer waiting for the sleep to finish, but the process just isn't killing Commented Jul 11, 2018 at 16:50
  • Actually replacing it with the -f appears to be having the desired effect Commented Jul 11, 2018 at 17:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.