Pages

Thursday, December 5, 2013

Install cron / crontab pada ubuntu


cron job
Install Cron 

$sudo apt-get install cron

atau
boleh dari aplikasi  'Synaptic Package Manager'





Perintah yang yang di gunakan pada Crontab :
- crontab -e  : Berfungsi untuk mengubah dan membuat Crontab Baru
- crontab -l   : Berfungsi untuk melihat isi dari Crontab yang telah kita buat
- crontab -r  : Berfungsi untuk menghapus Crontab


membuat cron job

format penulisan job seperti dibawah ini :

*     *     *     *     *  command to be executed
-     -     -     -     -
|     |     |     |     |
|     |     |     |     +----- hari (0 - 6) (minggu=0)
|     |     |     +------- bulan (1 - 12)
|     |     +--------- tanggal (1 - 31)
|     +----------- jam (0 - 23)
+------------- menit (0 - 59)




Cara membuatnya :

$sudo crontab -e

tampilanya :
Select an editor.  To change later, run 'select-editor'.
  1. /bin/ed
  2. /bin/nano        <---- easiest
  3. /usr/bin/mcedit
  4. /usr/bin/vim.tiny
Choose 1-4 [2]: 4

ket : pilih proses edit filenya  terserah anda dan enter

Menambahkan  job baru pada bagian bawah

Tampilan Default :
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   comman


kemudian tambahkan job berikut ini pada bagian bawahnya.

10 8 * * * tar -zcf /home/kusdi/cron/test.tar.gz /home/kusdi/cron/
12 8 * * * cp /home/kusdi/cron/test.txt /home/kusdi/cron/text_cron.txt


Artinya :
10 8 * * * tar -zcf /home/kusdi/cron/test.tar.gz ....     artinya  berjalan setiap hari, setiap bulan, setiap tanggal 1-31 , jam 08:10
12 8 * * * cp /home/kusdi/cron/test.txt .....             artinya  job 2 berjalan setiap hari, setiap bulan, setiap tanggal 1-31 , jam 08:12


Selamat Mencoba






No comments:

Post a Comment