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!

Can 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.

I'm using FreeBSD 4.2-RELEASE, not sure of the procedure to do autostart, i have not encountered this type of 'rc' directory stucture/configuration.

Thanks a bunch!(in advance)

JayBot "Always know what you say, but don't always say what you know!"
 
Any command you put in /etc/rc.local will execute upon reboot. By default, this script will run with "root" permissions, but you can su to another user in this manner:

su -l username -c "script execution string"

This will allow the script to run under the user permissions for "username" including all of the environment variables for that user and login class.

I also refer you to my posts in the this thread: thread93-97423

To make the script run as a daemon, I should know a little more about the script. Maybe someone else can help here, but I don't know if there is a simple default option for this. If the problem is that the script is outputting text data on terminal, then you could just redirect output to a logfile of some sort, using the > pipe. Something like:

su -l username -c "script execution string > /path/logfile.txt"

But you would probably also want the "&" in there. A standard way I've seen a lot of Unix shell scripts run is"

su -l username -c "script execution string > /path/logfile.txt 2>&1 &"

As I understand it, the above forces both standard output and standard error from the executed program to be appended into the file "logfile.txt". For example, one possible startup script for PostgreSQL is:

postmaster -D /usr/local/pgsql/data > logfile 2>&1 &

(The -D tells the program "postmaster" to get its data from /usr/local/pgsql/data, and append all output or errors to "logfile".)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top