Tuesday, May 17, 2011

Crontab

CRON is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix , solaris. Crontab (CRON Table) is a file which contains the schedule of cron entries to be run and at specified times.

Put this script at /etc/crontad

00 3 * * * root /sbin/reboot


------------------------------------------
Other way
------------------------------------------

Cron is the process for executing commands at a scheduled time.
Crontab is the facility to schedule cron jobs.
Cron jobs can be run by any user, but because you want to reboot, you'll need to do this as root.

Edit the cron table:
# crontab -e

Now you are in vi, editing the cron table. Add a line like:

0 1 * * * shutdown -r now >/dev/null

This command says, when the minute is 0 and the hour is 1, execute the command "shutdown -r now"
and send any standard output to /dev/null (which cause the output to be thrown away).

If you wanted this to happen on only Monday and Friday, you'd change one of the asterisks
(first one I believe) to 1,5 (sunday is 0). Do a man on crontab for more details.

How to add a swap file in Linux

In Linux, as in most other Unix-like operating systems, it is common to use a whole partition of a hard disk for swapping. However, with the 2.6 Linux kernel, swap files are just as fast[7] as swap partitions, although Red Hat recommends using a swap partition. The administrative flexibility of swap files outweighs that of partitions; since modern high capacity hard drives can remap physical sectors, no partition is guaranteed to be contiguous. You can add swap file as a dedicated partition or use following instructions to create a swap file.

Procedure to add a swap file

You need to use dd command to create swapfile. Next you need to use mkswap command to set up a Linux swap area on a device or in a file.

a) Login as the root user

b) Type following command to create 512MB swap file (1024 * 512MB = 524288 block size):
# dd if=/dev/zero of=/swapfile1 bs=1024 count=524288

c) Set up a Linux swap area:
# mkswap /swapfile1

d) Activate /swapfile1 swap space immediately:
# swapon /swapfile1

e) To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using text editor such as vi:
# vi /etc/fstab

f) Append following line:
/swapfile1 swap swap defaults 0 0

So next time Linux comes up after reboot, it enables the new swap file for you automatically.

g) How do I verify swap is activated or not?
Simply use free command:
$ free -m