Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

How to run script automatically on reboot as root user?

Shell Programming and Scripting

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  
Part Time Freelancer
Join Date: Nov 2012
Last Activity: 1 September 2017, 4:34 PM EDT
Posts: 1,790
Thanks: 110
Thanked 628 Times in 558 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: 22 September 2017, 5:42 PM EDT
Location: Saskatchewan
Posts: 22,417
Thanks: 1,126
Thanked 4,237 Times in 3,917 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 12:51 PM..
Sponsored Links

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 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 07:02 PM.