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.
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.
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 &
cmd & disown works too, since the & is treated like a ; command separator. The disown command removes the connection between the bash shell session and the backgrounded command.
– lornix
Jul 14 '12 at 20:34
nohup creates a file when it runs, for me, so I added > /dev/null to ignore the output.
– Andrew
May 10 '23 at 21:42
nohup nor & disown are working for me unless I put read on the next line, to require me to press Enter to close the terminal. If I just have a .sh file without read, the terminal opens and closes real fast, without launching the application. (Of course, I can still close the terminal and the application continues running.) Why is that, and how do you fix it? Thanks
– Andrew
May 10 '23 at 21:46
nohup/disown-ed application?
– Andrew
May 11 '23 at 17:36
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.
Put a "&" character after your command.
e.g:
/home/your/script.sh &
/home/your/script.sh -- as it was not detached from its "parent", but just "backgrounded". Use nohup to detach it for real.
– Izzy
Jul 13 '12 at 13:05
nohup -- which also logs all (now invisible) output into a file called nohup.out located in the directory you started the command from.
– Izzy
Jul 13 '12 at 14:10
jobs command. Quite often i want to be able to get back to the shell process after backgrounding it.
– djangofan
Dec 07 '18 at 19:17
screen command for this. Type screen to open a new "session" run your things and close the terminal, the command will still be running in background. If you want to come back to this session just type screen -r
– Flinth
Dec 08 '18 at 23:27