LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-30-2014, 10:13 AM   #1
hnasr2001
Member
 
Registered: Nov 2012
Posts: 98

Rep: Reputation: Disabled
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

Last edited by hnasr2001; 12-30-2014 at 10:50 AM.
 
Old 12-30-2014, 02:01 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,153

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
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.
 
Old 12-30-2014, 05:35 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
If your version of cron is new enough, you can stick the script in the user's crontab using the "@reboot" directive.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
su to another user to run script ust Linux - Newbie 1 12-11-2012 11:56 PM
Run a script as any user Hi_This_is_Dev Linux - General 5 09-26-2010 08:57 AM
Is a script, run at boot time from init.d, run with root authority? tmbrwolf53 Linux - Server 2 03-31-2007 08:15 PM
How to run a script with a boot/reboot with the ownership of a user avijitp Linux - Server 2 11-03-2006 09:29 AM
how do I make sure that the user that is going to run the script is a root user??? nikold01 Linux - General 3 09-10-2004 07:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration