Hey guys. How can i run my SH script in the background, like a daemon. Thanks in advance!
Hey guys. How can i run my SH script in the background, like a daemon. Thanks in advance!
Registered Ubuntu user #25321
If the script is called myscript.sh, then run
Code:myscript.sh &
If you run it from a terminal you will also need to use disown to keep it running after you close the terminal:
Code:my_script.sh & disown exit
Don't try to make something "fast" until you are able to quantify "slow".
Vor, thanks for pointing out the 'disown' command -- I didn't know about that. I've always used nohup. Is that the same?
Also, just out of curiosity, I saved this script as 'test.sh':
And ran it from a gnome-terminal like this:Code:#!/bin/sh while true ; do echo "Hi!" >> ~/test/a; sleep 2 done
I then closed the gnome-terminal, and looked inside ~/test/a. It was still printing 'Hi!'s!Code:test.sh &
Then I logged out of my GNOME session, got to the GDM window, pressed Ctrl-Alt-F2, and logged in at a text terminal. The tesh.sh script was still printing more 'Hi!'s in ~/test/a!
Is this the effect of some configuration option I don't know about, or is this normal?
or nohup ...
Code:nohup script.sh &
There are two mistakes one can make along the road to truth...not going all the way, and not starting.
--Prince Gautama Siddharta
#ubuntuforums web interface
alt+f2 if you don't want to open a terminal to do it.
add it to /etc/init.d and update init.d to run it on login
Registered Linux User: 482377
MacBook (1,1) - OS X Leopard
ASUS P5LD2 - Core 2 Duo 3.0GHz - 2GB Corsair RAM - Nvidia 8800GT - Ubuntu 9.04 / Windows 7 Professional
There are two mistakes one can make along the road to truth...not going all the way, and not starting.
--Prince Gautama Siddharta
#ubuntuforums web interface
Any ideas where I should look to find out why my terminal has nohup/disown always on?
I checked with pstree and found that when I run test.sh its parent starts as bash (spawned by gnome-terminal), but when gnome-terminal is closed, test.sh's parent jumps to init.
I checked my .bashrc and .profile, and nothing jumped out at me as the culprit -- though I'm not great at understanding shell stuff.
I also am researching shopt, but I'm having trouble even finding documentation on what all the options mean.
Bookmarks