BOSS-LINUX, Backup Script-II

In the first part we tested all commands one by one to compress the working folder and copy the compressed tar file to USB disk. Now its time to put these commands in a file so as to run them in order.

Open gedit and type the basic script for test. We first ensure that scripts are running properly in your BOSS-LINUX installation. Your first script should look as follows…

#!/bin/bash
# My Backup script

echo "My Backup Script"
echo "Press Enter To Exit"
read

The first line of the script is important. This is a special clue given to the shell indicating what program is used to interpret the script. In this case, it is /bin/bash. Other scripting languages such as perl, awk, tcl, Tk, and python can also use this mechanism. Next is the comment which is a kind of remark. Comments will be ignored by the shell.

After that we use echo to display some messages. Using these messages you can inform the user about your script and what the script does. You may also echo step by step report of the commands which are being run by shell.

The last command read suspends the script unless the user hits enter. This is a simple way to  give time for the user to read the earlier messages given by echo. Without read the script would run very fast and exit the terminal in a fraction of a second. So it would be practically impossible to go through various echo messages.

Save this file as backup.sh If you now double click on this file from nautilus, the script won’t run but opens for editing. To make this file runnable, right click the file from Nautilus and then open the “properties” dialog. Tick execute as program.

Now try to run the script by double clicking on it.

Once we run the test script, the content can be replaced by our ready commands. Thus we have the final script which looks like the following.

#!/bin/bash
# My Backup script
set -x #echo on
echo "Copy 44-HTML"
tar -czf htmlcode.tar.gz /home/milind/Important/44-HTML
cp htmlcode.tar.gz /media/Milind
echo "Press Enter To Exit"
read

The set -x switches the echo mode on. This will show each command on the terminal as it is executed by the shell. This script should do your backup work as expected.

In the next part BOSS-LINUX, Backup Script-III we will create a shortcut to our script as assign an icon to it. Then we will put this shortcut on desktop. This has the added benefit of running your script without opening shell. You can just double click the icon on desktop and take your backup.

Author’s Email : oak444(at)gmail(dot)com

 

 

Leave a comment