I have a series of commands that I want to use nohup with.
Each command can take a day or two, and sometimes I get disconnected from the terminal.
What is the right way to achieve this?
Method1:
nohup command1 && command2 && command3 ...
or Method2:
nohup command1 && nohup command2 && nohup command3 ...
or Method3:
echo -e "command1\ncommand2\n..." > commands_to_run
nohup sh commands_to_run
I can see method 3 might work, but it forces me to create a temp file. If I can choose from only method 1 or 2, what is the right way?
The
nohup
will apply only tocommand1
. When it finishes (assuming it doesn't fail),command2
will be executed withoutnohup
, and will be vulnerable to a hangup signal.I don't think this would work. Each of the three commands will be protected by
nohup
, but the shell that handles the&&
operators will not. If you logout beforecommand2
begins, I don't think it will be started; likewise forcommand3
.I think this should work -- but there's another way that doesn't require creating a script:
The shell is then protected from hangup signals, and I believe the three sub-commands are as well. If I'm mistaken on that last point, you could do: