Automaattiset tehtävät


Linuxissa voit kirjoittaa skriptejä jotka suoritetaan tiettynä aikana.



Ajoitettujen tehtävien konfigurointi


Konfigurointitiedosto cron-tehtäviä varten on /etc/crontab. Se sisältää seuraavat rivit:



SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/



# run-parts

01 * * * * root run-parts /etc/cron.hourly

02 4 * * * root run-parts /etc/cron.daily

22 4 * * 0 root run-parts /etc/cron.weekly

42 4 1 * * root run-parts /etc/cron.monthly



Ensimmäiset neljä riviä määrittelevät ympäristön ajoitetuille tehtäville. SHELL-muuttuja kertoo mitä shell:iä käytetään (esimerkissä: BASH). PATH-muuuttuja kertoo käytettävän polun komentojen suorittamiselle. Tehtävien tulokset sähköpostitetaan MAILTO-osoitteeseen. Tyhjä argumentti (MAILTO="") ei lähetä mitään. HOME-muuttujalla voi valita kotihakemiston josta komennot ja skriptit ajetaan.

Jokainen rivi /etc/crontab-tiedostossa on muodossa:



minuutti tunti päivä kuukausi viikonpäivä komento



  • minuutti — kokonaisluku väliltä 0-59

  • tunti — kokonaisluku väliltä 0-23

  • päivä — kokonaisluku väliltä 1-31

  • kuukausi — kokonaisluku väliltä 1-12

  • viikonpäivä — kokonaisluku väliltä 0-7 (0 on sunnuntai)
  • komento — Komento voi olla erillinen (esim. ls /proc >> /tmp/proc) tai erillinen skripti.


"*"-merkkiä voi käyttää jokerimerkkinä. Esimerkiksi * kuukauden kohdalla suorittaa komennon joka kuukausi.
"-"-merkki määrittelee jonon. 1-4 tarkoittaa jonoa 1,2,3,4.





A list of values separated by commas (,) specifies a list. For example, 3, 4, 6, 8 indicates those four specific integers.



The forward slash (/) can be used to specify step values. The value of an integer can be skipped within a range by following the range with /. For example, 0-59/2 can be used to define every other minute in the minute field. Step values can also be used with an asterisk. For instance, the value */3 can be used in the month field to run the task every third month.



Any lines that begin with a hash mark (#) are comments and are not processed.



How to start an automatic execution of a script on hosting plan?



First it needs to be verified whether the script works in shell mode. In order to do it you need to place #!/usr/local/bin/php, for php script, #!/usr/bin/perl, for perl, lub #!/bin/bash, for shell script. Then use chmod 700 skrypt.cgi command for the script. If you have telnet/ssh access you may check it by./script.cgi.



Remember to use cd /home/login command at the beginning of the script. You may use absolute path to indicate

the file.

After verification of the script in shell mode, you need to contact Client Service Panel by email and provide the following data:



  • domain name

  • absolute path to the script (e.g. /home/login/scipt.cgi),

  • hour and day of the script execution