Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I auto-run a script in 'deamon' mode after a reboot???

Status
Not open for further replies.

JaybOt

Programmer
Apr 18, 2001
101
GB
Hi people,

I have a script that i want to run in the background, i don't want to use '&', and the user my 'deamon' runs as must be able to send mail/create files.

I also need my script to start automaticaly when the system reboots. I know this is done with 'rc.XXX' files/directory but can anyone tell me more?

Which 'rc' file do i use, whats the command line i should use to run my program in 'deamon' mode as described above.

Thanks a bunch!(in advance)

JayBot "Always know what you say, but don't always say what you know!"
 
Ok, I don't know what OS you're on, I assume a linux of some sort, but regardless as long as it's UNIX these instructions should help you out. You will want to review the manpages for the at command and the daemon command. I have a script which moves named files to a hidden wastebasket and I've put it in daemon mode. It looks like this:

#!/bin/bash
# del - move named files to a hidden wastebasket
#
#
WASTEBASKET=$HOME/.junk #must create .junk directory.
touch $*
mv $* $WASTEBASKET


Now, I use a simple daemon script to clean up on friday's

#!/bin/bash
#
# fridel - housekeeping daemon for wastebasket
#
cd ${WASTEBASKET:-$HOME/.junk}
find . -atime +7 -exec rm -r {} \; 2> /dev/null

at midnight friday <<!
daemon
!


Now all you have to do is put these in /etc/rc.d/init.d
and make it executable and provide a chkconfig statement like this one taken from /etc/rc.d/init.d/network on by box
#!/bin/bash
#
# network Bring up/down networking
#
# chkconfig: 2345 10 90
# description: Activates/Deactivates all network interfaces configured to #
# probe: true

The chkconfig statement updates and queries runlevel information for system services. You give the description of the script and you're ready to go. H:)pe this helps.
d3funct
zimmer.jon@cfwy.com
The software required `Windows 95 or better', so I installed Linux.

 
As far as the 'rc' scripts are concerned, you would normally put these in /etc/rc2.d with a name like Snn<filename> or Knn<filename> depending upon whether you're starting (S) or killing (K) the process, the latter being carried out when shutting your system down. The nn part refers to whereabouts in the startup or shutdown process you wish your program or whatever to take place, 99 being very late in the procedure. Have a look in /etc/rc2.d to get an idea of priorities assigned to other processes.

Some of these files may be links, but there's nothing to stop you from creating the file within the rc2.d directory itself using vi. Give root execute permission on the file and voila, a shutdown or startup script sees the light of day.
 
Hi,

the command &quot;daemon&quot; and &quot;chkconfig&quot; that d3funct mentioned, are RedHat-Linux-specific, they probably won't work on another system.

The runlevel-script should definitely go into the &quot;/etc/init.d&quot; or &quot;/etc/rc.d/init.d&quot;-Directory, and a link from there to the corresponding rcX.d-Directory, depending on the runlevel you use for normal operation.
You can check that with &quot;runlevel&quot; or may be &quot;who -r&quot; for the actual state and look into &quot;/etc/inittab&quot; for the default-runlevel at boot-time.

mbr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top