0

I'm trying to start a trim command on a bunch of servers remotely since these are appliances and we lose support if you change anything like cron jobs locally.

I'm trying to do this:

ssh [email protected] "nohup fstrim /data &"

That is executed but the problem is the secure shell is kept open despite nohup and everything. Can I force ssh to just drop the command and pull out immediately?

Just found a similar request via google. There it was solved with

screen -d -m ./script

Unfortunately screen isn't available on the appliances.

1

3 Answers 3

3

If you've got screen installed on the remote servers, try this, which will run the fstrim command inside a detached screen session. As far as ssh is concerned this will appear to exit immediately.

ssh [email protected] screen -S fstrim -md fstrim /data

You can reattach to the session with

ssh -tt [email protected]. screen -r fstrim

and disconnect again with Ctrl a(Ctrl) d

The reason your initial command isn't working is because nohup can see that stdout isn't a terminal and keeps the descriptor open for writing. (If you'd used ssh -tt it would have created a pseudotty on the remote side and nohup would have seen a terminal.) By redirecting stdout explicitly you can get the process to run in the background as you'd expect:

ssh -fn [email protected] "nohup fstrim /data >nohup.out &"

Read man nohup for the gory details on this now you know what you're looking for.

0
1

Never mind, believe I found the solution:

ssh [email protected] "nohup fstrim /data > /dev/null &"
1
  • My answer explains the why of this. Commented Oct 7, 2019 at 14:33
1

Is atd running on the appliance? If so, you can schedule an immediate at job:

ssh [email protected] "echo 'fstrim /data' | at now"

Your remote session will terminate immediately, because all it's doing is scheduling the job. The atd daemon takes care of actually executing it.

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.