Script is sequence of instructions for which we have a repeated use. Using the cron facility, scripts can be used to automate the tasks. It seems difficult to start but is the simplest thing to learn. We can make our work easy with shell scripting. Here, I’m using a simple example to explain its working:-
Problem: I want to change the brightness on my screen by running a script automatically during boot.
Creating a Script:
- First of all, install xbacklight to manage the brightness of your screen. Use the following command:
$ sudo apt-get install xbacklight inotify-tools
- Now, create a bash file using any editor with an extension of .sh and add commands in that. Here, I made a file brightnessControl.sh
- Write the code as shown and save this.
$ chmod +x brightnessControl.sh
- To run this use,
Run a script when system boots as root:
- Add permissions first off.
$ chmod 755 brightnessControl.sh
- Open Statrup Applications> Add new > sh /etc/init.d/brightnessControl.sh
- Save and close. And restart. It’s done.
Create symbolic link-
for example if you wanted to run a program in the graphical run level 2, the default run level for Ubuntu, you would place it in the
/etc/rc2.ddirectory. You just cannot place it the directory, you must signify when it will run by indicating the startup with an “S” and the execution order is important. Place it after everything else that is in the directory by giving it a higher number.
If the last script to be run is
rc.localand it is named
S99rc.localthen you need to add your script as
ln -s /etc/init.d/brightnessControl /etc/rc3.d/S99brightnessControl
Also, make sure brightnessControl file is executable and run this command-
$ sudo update-rc.d brightnessControl defaults
So, with shell scripts you can make your work easy.