I have the following command set which I sometimes run on my VPS. Basically it works fine; It runs in the background and does what I need.WB=$$; (       sleep 2h;       echo Removing PMA and exiting;       phpdismod mcrypt mbstring;       apt-get purge phpmyadmin -y;       service apache2 restart;       sed -i 's/Include \/etc\/phpmyadmin\/apache.conf/ /g' /etc/apache2/apache2.conf;       kill $WB) &The only thing I miss:The only thing I miss in this command set is a nohup. It's important for me to use nohup in case I've closed the session or had a power outage in my end --- With a nohup, I promise the command set will still be scheduled for execution in the VPS, in such cases.How could I add a nohup to this command set?
How could I add nohup to a bash command set?
nohup
You have a few options, all of which preserve your requirement of terminating your foreground session at the end (which you do with kill $WB).If possible, use tmux (or screen). It's the most obvious solution for your use case: a disconnection on your end will just cause a detachment of the tmux session, thus the commands you issued will not stop; after that, you could even re-attach to that session if you wanted to check its output (instead of tail -f nohup.out). You wouldn't even need the kill $WB trick, as every single command is executed in the foreground, so a simple exit will suffice. Summary: ssh into your VPS -> execute tmux -> type the commands you listed (without the WB=$$; (, the ) & at the end and substituting kill $WB with a simple exit) -> disconnect, detach and re-attach as neededIf you can't or don't want to use tmux, put your commands in a file. The problem here is basically that nohup can't execute grouped commands (the concept of subshell is exclusive to bash, you can't execute one with nohup), so you could put your code e.g. in the /opt/myscript.sh file:#!/bin/bash#You will pass the PID of the foreground shell as its first argumentWB=$1sleep 2h;echo Removing PMA and exiting;phpdismod mcrypt mbstring;apt-get purge phpmyadmin -y;service apache2 restart;sed -i 's/Include \/etc\/phpmyadmin\/apache.conf/ /g' /etc/apache2  /apache2.conf;kill $WBThen you can execute it with nohup /opt/myscript.sh $$ &If you can't or don't want to put them in a file, just execute them like this: nohup bash -c  ...your commands here... ; kill $$ &. The $$ here will still be referring to the outer foreground shell, as it is substituted before it is executed as the bash -c argument.As your script starts with a 2 hour sleep, you may want to consider the at program. You can execute at now + 2 hours and then type the commands you want to execute 2 hours from then (with 1 minute granularity). Once you have typed all the commands you need, you can exit the at shell with Ctrl+D and check with atq that your command sequence has been scheduled for execution.You can also execute your script as a heredoc. It's basically the same as option 3, but instead of specifying your commands as the -c argument, you give them to bash's standard input. Just be aware that if your script expects arguments, you must specify them during the call to bash, like this:nohup bash -s -- firstArgument secondArgument <<'EOF' &....paste your code here.....EOF