Sponsored Content
Top Forums Shell Programming and Scripting How to run script automatically on reboot as root user? Post 302770102 by Corona688 on Thursday 14th of February 2013 12:44:13 PM
Old 02-14-2013
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 01:51 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Run non-root script as root with non-root environment

All, I want to run a non-root script as the root user with non-root environment variables with crontab. The non-root user would have environment variables for database access such as Oracle or Sybase. The root user does not have the Oracle or Sybase enviroment variables. I thought you could do... (2 Replies)
Discussion started by: bubba112557
2 Replies

2. Shell Programming and Scripting

run a script on logout by a non-root user

hi , i need to run a script that delete files when i logout as a user other than root user . I have tried out using .bash_logout but that doesnt seem to work , so any alternative for this to be done. Thanks in advance, Harsha (6 Replies)
Discussion started by: harsha10
6 Replies

3. Shell Programming and Scripting

How a normal user run a script including root privileaged commands

Dear all Ihave written a script in Hpux9.0, the ecript is working fine if I run it from root command prompt But when I am running it thru /etc/profile or /user/.profile and login as a normal user, the owner of the process running the script is the normal user & hence cant run a root privileaged... (7 Replies)
Discussion started by: initin
7 Replies

4. UNIX for Dummies Questions & Answers

How to allow access to some commands having root privleges to be run bu non root user

hi i am new to unix and i have abig task. i have to \run particular commands having root privileges from a non root user. i know sudo is one of the way but i need sum other approach kindly help Thanks (5 Replies)
Discussion started by: suryashikha
5 Replies

5. UNIX for Dummies Questions & Answers

Script to automatically reboot to newly compiled kernel with fallback

Hi, I'm new here. Just started playing around with kernel compilation. I need a little bit of advice. I'm trying to do a bash script to automatically compile a kernel package and reboot to that new kernel by default, with fallback to the old kernel. So far, I'm getting stuck at the part... (0 Replies)
Discussion started by: tridus_08
0 Replies

6. Shell Programming and Scripting

Get current logged in user from a script run as root.

Ok, so, in order to install some dependencies of a program I made, a script has to be run as root. The thing is that I have to copy some things into the home folder of currently logged in user, but the variable $HOME returns '/root' and the $USER returns 'root' :( Is there any way to see who is... (7 Replies)
Discussion started by: hakermania
7 Replies

7. Shell Programming and Scripting

Can root user run chmod 000 permission shell script?

Hi, I have a shell script file which is set to access permission 000. When I login as root (sudo su) and try to run this script, I am getting the Permission denied error. I have read somewhere that root admin user can execute any kind of permission script. Then why this behavior? However, I can... (1 Reply)
Discussion started by: royalibrahim
1 Replies

8. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

9. Shell Programming and Scripting

Script to run commands as root user

Hello I have a script which is working fine so far to generate HTML file. Now i am wondering how do i include a syntax where it can change itself to root user and execute a specific commands as root user. Please help, Thanks in advance. -Siddhesh (2 Replies)
Discussion started by: Siddheshk
2 Replies

10. Shell Programming and Scripting

Run a script before and after reboot automatically and send output to two locations.

Hello Team . I am working a health check script ( bash) to run on linux server ( RedHat) and requirements are 1. The o/p of script need to be send to two diff files . I am testing with tee command . But I am not successful yet , any recommendations if that is the right approach ? 2. The same... (2 Replies)
Discussion started by: Varja
2 Replies
CRONTAB(1)						    BSD General Commands Manual 						CRONTAB(1)

NAME
crontab -- maintain crontab files for individual users (V3) SYNOPSIS
crontab [-u user] file crontab [-u user] { -l | -r | -e } DESCRIPTION
The crontab utility is the program used to install, deinstall or list the tables used to drive the cron(8) daemon in Vixie Cron. Each user can have their own crontab, and they are not intended to be edited directly. (Darwin note: Although cron(8) and crontab(5) are officially supported under Darwin, their functionality has been absorbed into launchd(8), which provides a more flexible way of automatically executing commands. See launchctl(1) for more information.) If the /usr/lib/cron/cron.allow file exists, then you must be listed therein in order to be allowed to use this command. If the /usr/lib/cron/cron.allow file does not exist but the /usr/lib/cron/cron.deny file does exist, then you must not be listed in the /usr/lib/cron/cron.deny file in order to use this command. If neither of these files exists, then depending on site-dependent configuration parameters, only the super user will be allowed to use this command, or all users will be able to use this command. The format of these files is one username per line, with no leading or trailing whitespace. Lines of other formats will be ignored, and so can be used for com- ments. The first form of this command is used to install a new crontab from some named file or standard input if the pseudo-filename '-' is given. The following options are available: -u Specify the name of the user whose crontab is to be tweaked. If this option is not given, crontab examines ``your'' crontab, i.e., the crontab of the person executing the command. Note that su(1) can confuse crontab and that if you are running inside of su(1) you should always use the -u option for safety's sake. -l Display the current crontab on standard output. -r Remove the current crontab. -e Edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables. The specified editor must edit the file in place; any editor that unlinks the file and recreates it cannot be used. After you exit from the editor, the modified crontab will be installed automatically. FILES
/usr/lib/cron/cron.allow /usr/lib/cron/cron.deny DIAGNOSTICS
A fairly informative usage message appears if you run it with a bad command line. SEE ALSO
crontab(5), compat(5), cron(8), launchctl(1) STANDARDS
The crontab command conforms to IEEE Std 1003.2 (``POSIX.2''). The new command syntax differs from previous versions of Vixie Cron, as well as from the classic SVR3 syntax. AUTHORS
Paul Vixie <paul@vix.com> BSD
December 29, 1993 BSD
All times are GMT -4. The time now is 06:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy