Basic concepts ...
To run two scripts after each other you place a semi colon between them: script1 args ...; script2 args ... or in a script you can also put them on two lines like this:
#!/bin/sh script1 args ... script2 args ...
This also works if you want to run them in the background. You just put them in a subshell and put the subshell in the background: (script1 args ...; script2 args ...) & or:
#!/bin/sh ( script1 args ... script2 args ... ) &
If you want to run the second script only if the first script did exit successful (with code 0) you can replace the semi colon with &&: script1 args ... && script2 args ...
... with nohup
But nohup wants to run one command and a subshell is not a single command, it is a shell construct that only works in the shell. But we can start a new shell that executes the two scripts, pass that as one command to nohup and put all this together in the background:
#!/bin/sh nohup sh -c 'script1 args ...; script2 args ...' &
If you have variables in args ... you will have to use double quotes and you have to take special care to escape them correctly so here is another way:
... with double fork
The shell only knows and cares about it's direct children. You are warned if there are still processes running in the background when you try to exit, and these direct children are killed if you really exit the shell. The solution is to put a subshell in the background that itself puts your command in the background. Your shell will only know about the subshell and not about the command. But you can not rely on the redirection magic of nohub like this and have to set up your own redirection:
#!/bin/sh ( # outer subshell, will be known to your shell ( # inner subshell, "hidden" from your interactive shell script1 "$args" ... > ~/script1.stdout.log 2> ~/script1.stderr.log script2 "$args" ... > ~/script2.stdout.log 2> ~/script2.stderr.log # note that you can do normal quoting here ) & ) &
Ctrl-CorCtrl-Z) the running program in a terminal again you can have a look atscreenandtmux.screenortmuxand run the scripts from there asscript1.sh $arg1; script1.sh $args2?