run a script during boot up as a user
Operating system: Redhat 5.10
I have a script called radmon_daemon and a symbolic link to it at /etc/init.d/ ln -s /usr/tech/radmon/radmon_daemon radmond the script run as root! Is there a way to run it as user? I have the script posted bellow; ------------------------ radmon_daemon script; ------------------------ #!/bin/bash # chkconfig: 345 99 99 # description: Radmon daemon #Source Functions library . /etc/init.d/functions start () { echo " Starting radmon" # before we start let's make sure that only one radmon # program is running. # sudo killall -q .radmocscript_echoff sudo killall -q .radmonscript_echon sudo killall -q .radmon5 # Now lets start radmon cd /usr/tech/radmon #Need to be in directory for radmon to run properly /usr/tech/radmon/.radmonscript_echoff & echo echo "Radmon is started in background mode" echo "Enter command radmon in directory /usr/tech/radmon to bring up front" echo "/usr/tech/radmon/latestminute is generated every minute." echo } stop() { echo "Stopping radmon." cd /usr/tech/radmon #Need to be in directory for radmon to run properly sudo killall -q .radmonscript_echoff sudo killall -q .radmonscript_echon sudo killall -q .radmon5 } local() { echo echo "Shutting down radmon for local operation." cd /usr/tech/radmon #Need to be in directory for radmon to run properly sudo killall -q .radmonscript_echoff sudo killall -q .radmonscript_echon sudo killall -q .radmon5 echo "Re-starting local radmon in 5 seconds" sleep 5 /usr/tech/radmon/.radmon5 echo echo "Restart radmon in background in 5 seconds" echo "Radmon screen output is disabled" echo sleep 2 /usr/tech/radmon/.radmonscript_echoff & echo "Done!" } case "$1" in start) start ;; stop) stop ;; local) local ;; restart) stop start ;; *) echo "Usage: $0 {start|stop|local|restart}" esac exit 0 |
To start off please use code tags for your posted scripts, second all init scripts are run as root, if you want to run a command in a script a a particular user try using su to run the command, many deamons allow being run as a particular user, ( appache for instance ) but see the relevent man pages, or you can run the script when the user logs in by placing it in ~/.bash_profile, or if worze comes to worse just get the init script to call the real script as a specific usr again you will probably have to use su.
|
If your version of cron is new enough, you can stick the script in the user's crontab using the "@reboot" directive.
|
All times are GMT -5. The time now is 04:53 PM. |