Remote simulation and 'at' command

Hey,

Task seems to be quite easy, but I'm still a bit green in shell scripting. I hope you can help me a bit. I have to run some simulation at the distance by remote terminal.

Normally when I'm working on the server directly I just type:
mpirun -np 8 compressibleInterFoam -parallel > log.txt &

This command allows me to run the simulation on 8 cores working in parallel, put the output into the file log.txt and keep everything in the background. Thanks to this I'm sure that when I close the terminal window I don't stop the simulation.

Situation is similar when I'm doing this as a remote procedure. Then I just login via ssh login@server_address in terminal and then I use again above mpirun procedure. The only one difference is that when I close this terminal simply by closing window I'm not only stop the connection but either terminate the simulation ;( I ended up with idea of using 'at now' command, but I don't how to write proper procedure.

Maybe you know how to solve my problem?

nohup to the rescue. Run your command as

nohup mpirun -np 8 compressibleInterFoam -parallel > log.txt &

and you're all set.

sounds promising but no, even though I got some weird info

[piotr@uran condTank_2]$ nohup mpirun -np 8 compressibleInterFoam -parallel > log.txt &
[1] 19263
[piotr@uran condTank_2]$ nohup: ignoring input and redirecting stderr to stdout

it still terminates the process when I close my terminal.... that's strange ?!

How do you know it terminates? Is there an entry in the log file? Did you check with ps?

As for the message: it just tells you that nohup will ignore any keyboard input, and that error output on stderr will be sent to standard output (stdout) instead, and thus will ultimately end up in your log file too.

Hmmm I just run two terminals, and then I'm logging 2 times in each window. One window is used for remote commands and the other one for htop.

I can see every action I made in the first terminal by observing the htop in the second window. I see when the cpu load bars are rising due to mpirun action, and when they decreasing suddenly after closing 'remote commands' terminal.

---------- Post updated at 03:53 PM ---------- Previous update was at 12:17 PM ----------

Ok, I found the solution. It's screen command.

One can simply do as me. Type:
1) screen
2) here you can put any of your commands that suppose to stay in a background. I put here my:
mpirun -np 8 compressibleInterFoam -parallel > log.txt &
3) press ctrl + a + d // and you are free :slight_smile: you can close the terminal if you want or just logout

In order to get back to the screen, type:
1) screen -list // as a result you will get all of the screens and numbers of processes
2) screen -r <number> // reattach you to the screen denoted by number of the certain process.

Thanks for advice

Very interesting, iw as searching for something like that but didn't find and used AT ;).
Now, my question is if it's possible to detach the screen simultanuously; something like:

ssh screen --detach mycommand.sh

I found the -d option in the man but gives an error

There is no screen to be detached matching mycommand.sh.

Have you tried that?:

screen -d <number>

Let me give an example : when i type on the command line it's OK

local$>ssh Serveur
remote$>screen top &
remote$>screen -d
[remote detached]
[1]+  Done                    screen top
remote$>exit
Connection to Serveur closed.
local$>

But within a shell script like

#!/bin/bash
ssh dell1 screen <<< top &
screen -d 

I get the errors

There is no screen to be detached.
Must be connected to a terminal.

The solution :
Thanks to www.commandline.fu

ssh Serveur screen -d -m top