37

Is it possible to launch a command or Bash script exit terminal and NOT interrupt command?

My solution was to run cron at a specific time of day, but I'm sure there is something easier.

4 Answers4

69

To avoid exit signals propagating to child processes of the terminal and shell, run the command with nohup, i.e.:

nohup cmd &

To ignore all program output and avoid the nohup.out file, you can redirect stdout and stderr to /dev/null like this (with bash):

nohup cmd &> /dev/null &
Thor
  • 6,763
  • 1
  • 40
  • 44
7

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

Bruce
  • 171
6

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.

lejahmie
  • 169
3

Put a "&" character after your command.

e.g:

/home/your/script.sh &
Flinth
  • 360