nohup multiple sequential commands

Easiest solution: Create a shell script with

 #/bin/sh
 tar -zcf archive.tar.gz.tmp mydir
 mv archive.tar.gz.tmp archive.tar.gz

And use nohup myscript. Possibly with some extra documentation in the script.

(Yes, I am a sucker for documentation. Especially when working with multiple people or when you might someday leave the job and your successor needs to figure out why".)


An alternative might be to start a new shell for a subtask (in this case your tar and move)

nohup `$(tar -zcf archive.tar.gz.tmp mydir; mv archive.tar.gz.tmp archive.tar.gz)


Alternative 2:

nohup ```tar -zcf archive.tar.gz.tmp mydir ; mv archive.tar.gz.tmp archive.tar.gz```.

I really prefer the script though. The comments in it might be quite useful when you or someone else looks at he script in a few years and wonders why it was done this way.

On a unrelated note: How the heck do I post an anser with a backtick in it? (The command for a shell to 'use this command ; feed the output to another command as input`).


I think you need parentheses.

nohup $(tar -zcf archive.tar.gz.tmp mydir; mv archive.tar.gz.tmp archive.tar.gz) >/dev/null 2>&1 &


Maybe a bash wrap?

nohup bash -c 'tar -zcf archive.tar.gz.tmp mydir > /dev/null 2>&1 ; mv archive.tar.gz.tmp archive.tar.gz > /dev/null 2>&1' &

Tags:

Linux

Nohup