How to run script automatically on reboot as root user? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How to run script automatically on reboot as root user?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-14-2013
Akshay Hegde's Avatar
Akshay Hegde Akshay Hegde is offline Forum Advisor  
Forum Advisor
 
Join Date: Nov 2012
Last Activity: 27 July 2014, 2:03 PM EDT
Location: Goa / Bangalore, India
Posts: 1,418
Thanks: 72
Thanked 440 Times in 401 Posts
How to run script automatically on reboot as root user?

Hi friends,,,

I am running one server on Ubuntu 12.04 LTS 32-bit, some times my pc restarts automatically, with no reason, I have a script to start server which requires root password. in this directory


Code:
/myserver/start_server.sh

How can I do this ?

and some scripts I am having that I need to run daily once around 10.00 Am, for these scripts I need to change ownership from root to user in
Code:
 /dev/bull

while running script
Sponsored Links
    #2  
Old 02-14-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 27 July 2014, 10:58 PM EDT
Location: Saskatchewan
Posts: 18,978
Thanks: 748
Thanked 3,146 Times in 2,951 Posts
If you have cron running, you can add this line to root's crontab by running crontab -e as root:


Code:
@reboot /path/to/myscript

to have cron run your script on boot.

Beware that cron gives a minimal path. You may want to add . /etc/profile as one of the first lines in your script to ensure it can find all the common commands.

If you want to change permissions on devices, do so with udev's own config files, not manually changing them with a script -- udev is the system that sets the permissions in the first place, and may undo manual changes on a whim. On my system they're in /etc/udev/rules.d/ but YMMV.

Perhaps a udev rule like this:


Code:
KERNEL=="bull", GROUP="mygroup", MODE=0660

...matching the name the kernel (not /dev) gives it, assigning it to 'mygroup', and giving it group read-write permissions.

Last edited by Corona688; 02-14-2013 at 12:51 PM..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to run commands as root user Siddheshk Shell Programming and Scripting 2 02-08-2013 06:47 AM
Need to run a bash script that logs on as a non-root user and runs script as root damang111 Shell Programming and Scripting 2 12-23-2011 10:53 PM
Get current logged in user from a script run as root. hakermania Shell Programming and Scripting 7 08-18-2010 09:47 AM
How a normal user run a script including root privileaged commands initin Shell Programming and Scripting 7 01-20-2009 01:59 PM
run a script on logout by a non-root user harsha10 Shell Programming and Scripting 6 06-16-2008 03:14 PM



All times are GMT -4. The time now is 10:22 AM.