Friday, July 27, 2012

EXECUTE A LINUX COMMAND IN THE STARTUP WITH ADMIN PRIVILEGE

A script that need administrative privilege can't be simply added  to the startup session . Here is a simple way to do this

step-1:In the terminal type the command ' gksudo nautilus ' , to open the file browser as super user.

step-2:Go to the location /etc/init.d/  and create a file with .sh extension,
(eg:- mount.sh)

step-3:Again go to the terminal and make the file exicutable using the following commands
cd /etc/init.d
sudo chmod +x  filename.sh (replace filename with the name of your file)

step-4:Now open the file with your favorite text editor and  at the beginning write the following script to set the path
 #!/bin/bash
then write the command that you want to execute
note:no need for writing sudo at the beginning

step-5:save the file and in the terminal run the command

sudo update-rc.dmystartup.sh defaults 99
 
The argument 'defaults' refers to the default runlevel and '100'  means the script will get executed before any script containing number 101. Just run the command ls –l /etc/rc3.d/ to see all scripts with numbers.

No comments:

Post a Comment