Senin, 23 November 2009

Belajar Linux - Linux Crond Guide

1. Introduction
Every user as well as administrator of the linux system very often needs to execute some programs on regular basis. For example, an administrator may need to monitor a disk usage of a system. In this case a cron scheduler is very handy tool to achieve this. For example, if root needs to execute /usr/local/sbin/backup.sh script every Sunday at 2:36AM he would edit his crontab file as shown on the figure below:

# crontab -e


The format is simple, 6 fields separated with spaces or tabs. The rest of the line is the command, and it's parameters to be executed. The sixth field - user name (in blue) is used only in the system wide cron scheduler.















2. Cron job examples
Crontab Example 1: This crontab example runs updatedb command 35 minutes past every hour.

35 * * * * updatedb


Crontab Example 2: This crontab example runs /usr/local/bin/diskusage.sh every 5 minutes (e.g. 0, 5, 10, 15, ...).

*/5 * * * * /usr/local/bin/diskusage.sh


Crontab Example 3: This crontab example runs /usr/local/bin/diskusage.sh at 1:25 AM, 1:50 AM every Tuesday and on 15th of every month.

25,50 1 15 * 2 /usr/local/bin/diskusage.sh


Crontab Example 4: This crontab example runs /usr/local/bin/diskusage.sh at 2:00 PM on 10th of March, June, September and December.

00 14 10 3,6,9,12 * /usr/local/bin/diskusage.sh


Crontab Example 5: This crontab example runs '/usr/local/bin/diskusage.sh user@linuxconfig.sh' at 9.00 PM every Monday, Wednesday, Friday. Note: Using names for the week day and months is extension in some versions of crontab.

00 21 * * Mon,Wed,Fri /usr/local/bin/diskusage.sh user@linuxconfig.sh


Crontab Example 6: This crontab example runs /usr/local/bin/diskusage.sh every 5 minutes during the 5 working days (Monday - Friday), every week and month.

*/5 * * * 1-5 /usr/local/bin/diskusage.sh


Crontab Example 7: This crontab example runs /usr/local/bin/diskusage.sh every minute during the 4-th hour only in Sunday, every week and month. This is every minute from 0:00 till 0:59, then from 4:00 till 4:59, etc.

* */4 * * sun /usr/local/bin/diskusage.sh


3. System wide cron scheduler
As a Linux administrator you can also use predefined cron directories:

/etc/cron.d /etc/cron.daily /etc/cron.hourly /etc/cron.monthly /etc/cron.weekly


If root wishes to run backup.sh script once a week he will place backup.sh script into /etc/cron.weekly directory.

4. Cron Scheduler on user level
Every user can edit, view or remove his own crontab file. If the root user needs to change someone else's crontab file he must add '-u' option to specify the user name. To edit crontab file for user foobar we can use command:

# crontab -u foobar -e


Remove foobar's crontab file:

# crontab -u foobar -r


To view foobar's crontab content:

# crontab -u foobar -l

Membagi Resah

Ada resah yang ingin kubagi, namun tak kutemukan ruang kosong pada setiap hati yang kutemui. Sementara bebaris kata mengurai menjadi kalimat dalam buncahan rasa tanpa keteraturan gerak. Dan masih di sini sendiri mencari tempat sandaran untuk jiwa yang limbung.

Ada fragmen yang menunjukkan sisi lain tentang kemanusiaan. Ya, sisi manusia biasa yang tetap sedih meski dalam kamuflase senyum merekah. Tak bisa dibohongi, tak bisa dimanipulasi, dan tak bisa dibiarkan.

Kini, rasa yang sering terabaikan itu menuntut perhatian dari sang pemilik hati, yang telah meletakkannya dalam sangkar penghibur diri, dan mengatakan dengan enteng, "Semua akan baik-baik saja, tetap tersenyumlah dan nikmati harimu."

Namun sekali-kali tidak! Untuk saat ini. Karena kini aku harus berpacu dengan waktu. Diiringi resah yang mulai mencapai klimaksnya. Meski masih terpatri dalam keyakinan itu, bahwa Allah yang Maha Penyayang tak kan pernah membuat hambanya mengurusi urusannya sendiri.

Dan pertanyaan pun menggurat di rendah dasar hati, "Allahu Rabbi, apa yang sedang Engkau rencanakan untukku dengan urusan ini?"