Saturday, April 30, 2011



Command “tar” : It converts multiple files in a single file. [ file's extension is .tar ]

Options : We can check the options of this command by typing
# man tar
the main options are as follows :

a) -c : To create a back up.
b) -x : To restore back up.
c)-A : To concatenate. i.e. to add one tar file in another tar file.
d)-d : To compare the backup and the original directory whose backup is taken.
e)- -delete : To delete a file from tar file.
f)-r : To append a file at the end of tar file.
g)-t : To see contents of tar file.
h)-u : To update. Only new files in added to the tar file.

To check how commands work just create a “/backup” directory.
To take Back Up : run the below command,
# tar -cf /backup/backup1.tar /p1

Here, the back up of “/p1” directory is taken in file backup1.tar and stored at    “/backup” folder.

Now to see contents of “backup1.tar” file give command,
# tar -tf /backup/backup1.tar

Create new files in /p1 : To update backup, give command
# tar -uf /backup/backup1.tar /p1

Here only new files from /p1 are added to backup1.tar file.
To check new contents of tar file give same command,
# tar -tf /backup/backup1.tar

Now Take backup of another directory :
# tar -cf   /backup/backup2.tar    /abc

Now we add backup2.tar to backup1.tar :
# tar -Af /backup/backup1.tar /backup/backup2.tar

To see the contents :
# tar -tf /backup/backup1.tar

To Restore Backup : Give command,
# tar -xvf /backup/backup1.tar

If you don't want certain directories backup say “temp” then you can give command like,
# tar -cf /backup/newbackup.tar /p1 --exclude temp
where “temp” Is within “p1”.

If you don't want backup of certain files in a directory then just mention the names of these files in a new file and give path of that new file.
i.e. if we don't want files a1, a2, a3 then add these names in a new file say “abc”
# vim abc
a1 a2 a3
# tar -cf /backup/newbackup.tar /p1 -X abc

To convert backup in “.zip” format :
# tar -cvzf /backup/backup3.tar.gz /p1

To extract this backup :
# tar -xvzf /backup/backup3.tar.gz

Tuesday, April 12, 2011

Automated Tasks

                                             Automated Tasks

1] CRON :- It is a daemon to execute scheduled commands.
If we are having a script /home/ and we want to run it after every 2 minutes then,
There is a file in '/etc/crontab' Edit it and write there as,

*/2 * * * * sh /home/

save and exit


*/2 * * * * * command to be executed
-     - - -  - -
|     | | |  | |
|     | | |  |+- Year (optional)
|     | | | +----- day of week (0 - 6) (Sunday=0)
|     | | +---------- month (1 - 12)
|     | +--------------- day of month (1 - 31)
|    +-------------------- hour (0 - 23)
+------------------------- min (0 – 59)

Thus the script /home/ runs after every 2 minutes

If you want to run cron job by specific users then make a new file '/etc/cron.allow' and insert user names in it, those users which are allowed to set cron.
If user runs a cron jon then in “/var/spool/cron” directory there is a new file created by that users name. We can edit that file by “crontab” command.

i.e. $ crontab -e

to see scheduled cron, $ crontab -l
To restart service,
# service crond restart

To delete a job,

$ crontab -R (job no.)

                                       “at” Command

               This command Schedules other command (or job) to be ran at a particular time, such as a print job late at night.

“atq” : lists the user's pending jobs, unless the user is the superuser; in that case, everybody's jobs are listed. The format of the output lines (one for each job) is: Job number, date, hour, job class.

“atrm” : deletes jobs, identified by their job number.

You can check the other parameters for the command “at” by entering:
$ man at

Example :
$ at -m 02:50 < newatjob :  Run the commands listed in the 'newatjob' file at 2:50AM, in addition all output that is generated from job mail to the user running the task. When this command has been successfully enter you should receive a prompt similar to the below example.

                                    “batch” COMMAND
                   This command executes the other commands when system load levels permit; in other words, when the load average drops below 1.5, or the value specified in the invocation of atrun. It is similar to “at” in other respects.