RHEL 7 – Note RHCSA (cheat sheet)
– Linux può eseguire attività automaticamente e viene fornito con utilità per attività automatizzate:cron, anacron, at, batch .
– i processi cron possono essere eseguiti ogni minuto.
– Un processo cron pianificato viene saltato se il sistema è inattivo.
– anacron può eseguire un lavoro solo una volta al giorno.
– I lavori pianificati vengono ricordati ed eseguiti al successivo avvio del sistema.
– crond daemon ricerca più file e directory per i lavori pianificati:
1. /var/spool/cron/ 2. /etc/anacrontab 3. /etc/cron.d
Configurazione dei lavori cron
i lavori cron sono definiti in /etc/crontab.
Le voci crontab sono nella forma:
Minutes Hours Date Month Day-of-Week command
where: Minutes = [0 to 59] Hours = [0 to 23] Date = [1 to 31] Month = [1 to 12] Day-of-Week = [0 to 6] 0=Sunday - 6=Saturday command = a script file or a shell command. Other special characters can be used: - An asterisk (*) can be used to specify all valid values. - A hyphen (-) between integers specifies a range of integers. - A list of values separated by commas (,) specifies a list. - A forward slash (/) can be used to specify step values.
Altre directory e file cron
/etc/cron.d
– Contiene file con la stessa sintassi di /etc/crontab – accessibile solo dai privilegi di root
– Altre directory cron in /etc:–
cron.hourly cron.daily cron.weekly cron.monthly
– Gli script in queste directory vengono eseguiti ogni ora, giornalmente, settimanalmente o mensilmente, a seconda del nome della directory.
– Il /etc/cron.allow e /etc/cron.deny i file limitano l'accesso dell'utente a cron. Se nessuno dei due file esiste, solo root può usare cron.
Utilità di Crontab
– Utenti diversi da root possono anche configurare cron utilizzando l'utilità crontab.
– i crontab definiti dall'utente sono archiviati in /var/spool/cron/[nome utente] .
– Per creare o modificare una voce crontab:
# crontab -e
– Per elencare le voci nel crontab definito dall'utente:
# crontab -l
Configurazione dei lavori anacron
– i lavori anacron sono definiti in /etc/anacrontab .
– I lavori sono definiti da :
Period in days : frequency of execution in days Delay in minutes - Minutes to wait before executing the job job-identifier - A unique name used in logfiles command : a shell script or command to execute
esempio di file anacron :
SHELL=/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # the maximal random delay added to the base delay of the jobs RANDOM_DELAY=45 # the jobs will be started during the following hours only START_HOURS_RANGE=3-22 #period in days delay in minutes job-identifier command 1 5 cron.daily nice run-parts /etc/cron.daily 7 25 cron.weekly nice run-parts /etc/cron.weekly @monthly 45 cron.monthly nice run-parts /etc/cron.monthly
at e batch
– le utilità at e batch vengono utilizzate per la pianificazione di attività singole.
– il comando at esegue un'attività a un'ora specifica.
– il comando batch esegue un'attività quando la media del carico del sistema è inferiore a 0,8.
– il servizio atd deve essere in esecuzione per essere eseguito su o processi batch
– alla sintassi del comando :
# at time
– L'argomento ora accetta più formati:
HH:MM MMDDYY,MM/DD/YY or MM.DD.YY month-name day year midnight: At 12:00 AM teatime: At 4:00 PM now + time -- here time can be minutes, hours, days or weeks
– sintassi del comando batch :
# batch (at> promp is displayed)
– Il /etc/at.allow e /etc/at.deny i file limitano l'accesso degli utenti a at. Se nessuno dei due file esiste, solo root può usare cron.