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.

Thursday, March 31, 2011


                       RPM [ Red Hat Package Manager ]
To check options for command “rpm”
$ man rpm

To Remove a Package :-

$ rpm -e (package name)

To Install RPM :-

$ rpm -ivh (package name)

To check whether Package is Already Installed or not :-

$ rpm -qa |grep (Package name)

                        Quota Management

1] Quota is applied on Partition basis
2] Quota is applied on user basis
3] Quota is applied on group basis

a) Edit /etc/fstab file
b) In the 'mount' command of a specified partition after defaults, type usrquota or grpquota or both.
e.g. /dev/hdc3 /data ext3 defaults,usrquota,grpquota 0 0

c) Run the 'quotacheck -a' command :- this will create 'aquota.user & aquota.grp' files on the partitions, where the quota is applied.
d) To specify user quota run 'edquota' command

Create Partition on Disk :-

$ fdisk -l
$ fdisk /dev/sda2
        press 'm' for help
        press 'n' To create new Partition
        Enter last cylinder size :
        press 'w' write table to disk and exit
        press 'q' quit

After that restart your machine [ If you dont want to restart machine give command  “$ partprobe /dev/sda2”]

Then Format that partitions

$ mke2fs -j /dev/sda2

Then edit “/etc/fstab” file
/dev/sda2 /abc auto defaults,usrquota,grpquota 0 0

Save and Exit

Then mount that partition, for that

$ mkdir /test
$ mount /dev/sda2 /test

Then come to root and give command,

$ quotacheck -a

Then goto “/test” directory. There is a new file created 'aquota.usr'

Then give,
$ edquota -u (user name)
$ edquota -u user2

give this command in '/test' directory.

Here, the terms are,

Soft limits :- Warning period 2-3 days to delete data.
Hard Limit :- Above this limit user is not allowed to store data.
inodes :- Restriction on making files & directories. It has also soft & hard limit.
Blocks :- The limit upto which user can create data [e.g. 100Mb, 500Mb etc.]
i.e. Edit /etc/fstab
File System    Blocks    Soft     Hard    inodes    Soft     Hard
/dev/sda2          0           10        20          0             0         0

save & exit

For other user, $ edquota -u user2

To ON quota :-
$ quotaon /dev/sda2

Then login using user2 & try to make files or directories in /test directory. He can not make more files or directories.

After giving command '$ quotaon /dev/sda2' '' file is created in /test directory.

Some more Commands :-

$ man repquota

To OFF quota :      $ quotaoff /dev/sda2
To Check quota :   $ quotacheck -auvg