Unix/Linux Go Back    

Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

How to run script automatically on reboot as root user?

Shell Programming and Scripting

Closed Linux or Unix Question    
Thread Tools Search this Thread Display Modes
Old Unix and Linux 02-14-2013
Akshay Hegde's Unix or Linux Image
Akshay Hegde Akshay Hegde is offline Forum Advisor  
Forum Advisor
Join Date: Nov 2012
Last Activity: 24 November 2015, 4:57 AM EST
Location: Goa / Bangalore, India
Posts: 1,741
Thanks: 95
Thanked 599 Times in 539 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


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

while running script
Sponsored Links
Old Unix and Linux 02-14-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
Join Date: Aug 2005
Last Activity: 3 November 2015, 12:57 AM EST
Location: Saskatchewan
Posts: 21,164
Thanks: 937
Thanked 3,808 Times in 3,555 Posts
If you have cron running, you can add this line to root's crontab by running crontab -e as root:

@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:

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 01:51 PM..
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 07: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 11:53 PM
Get current logged in user from a script run as root. hakermania Shell Programming and Scripting 7 08-18-2010 10:47 AM
How a normal user run a script including root privileaged commands initin Shell Programming and Scripting 7 01-20-2009 02:59 PM
run a script on logout by a non-root user harsha10 Shell Programming and Scripting 6 06-16-2008 04:14 PM

All times are GMT -4. The time now is 08:18 PM.