Run Bash script in background and exit terminal
To avoid exit signals propagating to child processes of the terminal and shell, run the command with nohup
, i.e.:
nohup cmd &
Using screen
:
screen -S <session name> -d -m <your command>
after that you can quit the terminal, also you can reattach to it by:
screen -r <session name>
More info: reference
If you want to run a specific command or file every second or so in the background after exiting the terminal you could try this easy little thing;
nohup watch -n5 'bash script.sh' &
That would run scipt.sh every 5 seconds.