Академический Документы
Профессиональный Документы
Культура Документы
com
Originally published on
LinuxTechLab.com
There might arise a need to execute a command or scripts at
reboot or every time when we start our system. So how can
we do that, in this tutorial we are going to discuss just that.
We will discuss how we can make our CentOS/RHEL and
Ubuntu systems to execute a command or scripts at reboot
or at system startup using two different methods. Both the
methods are tested and works just fine,
In this method, we will use rc.local file located in /etc/ to execute our scripts and
commands at startup. We will make an entry to execute the script in the file & every
time when our system starts, the script will be executed.
But we will first provide the permissions to make the file /etc/rc.local executable,
$ sudo chmod +x /etc/rc.local
Now save the file & exit. Similarly we can execute a command using rc.local file but we
need to make sure that we mention the full path of the command. To locate the full
command path, run
$ which command
For example,
$ which shutter
/usr/bin/shutter
For CentOS, we use file /etc/rc.d/rc.local instead of /etc/rc.local. We also need to make
this file executable before adding any script or command to the file.
Note:- When executing a script at startup, make sure that the script ends with exit 0.
Method 2 Crontab method
This method is the easiest method of the two methods. We will create a cron job that
will wait for 90 seconds after system startup & then will execute the command or script
on the system.
To create a cron job, open terminal & run
$ crontab -e
If you think we have helped you or just want to support us, please consider these :-
Connect to us: Facebook | Twitter | Google Plus
LinuxTechLab.com