Passer au contenu principal
  • Passer des commandes rapidement et facilement
  • Afficher les commandes et suivre l’état de votre expédition
  • Profitez de récompenses et de remises réservées aux membres
  • Créez et accédez à une liste de vos produits

How to Configure Cron Jobs on RedHat Enterprise Linux (RHEL) 6

Résumé: This article provides information on how to configure cron jobs on RedHat Enterprise Linux (RHEL) 6.

Cet article concerne Cet article ne concerne pas Cet article n’est associé à aucun produit spécifique. Toutes les versions du produit ne sont pas identifiées dans cet article.

Symptômes

This article provides information on how to configure cron jobs on RedHat Enterprise Linux (RHEL) 6.

Cron jobs allow system administrators to schedule tasks. There are various ways you can configure these scheduled tasks. This article will cover using the 'cron' directories and using 'crontab'.



 

 

Table of Contents:

1. Cron Directories
2. Crontab


 

1. Cron Directories

  • There are four cron directories :
    • /etc/cron.hourly/
    • /etc/cron.daily/
    • /etc/cron.weekly/
    • /etc/cron.monthly/
       
  • Scripts in these directories will be executed on recurring basis (every hour, day, week, or month)
  • Perfect for scheduled tasks that do not need to be run on a specific day, specific time, etc.
  • Copy your script into the corresponding folder
  • Ensure scripts have the file permissions of 755 or -rwxr-xr-x
  • # chmod 755 scriptfile.sh
  • Default :
    • /etc/cron.daily starts at 0305 (3:05 AM)
    • /etc/cron.weekly starts at 0325 (3:25 AM)
    • /etc/cron.monthly starts at 0345 (3:45 AM)
       
  • View your current configuration :
  • # cat /etc/anacrontab
  • Use your favorite editor to edit '/etc/anacrontab'
  • Change your configuration :
  • What time the scripts will be executed in these directories :

 


 

2. Crontab

  • System administrators can use crontab to create cron jobs to schedule tasks to execute at a specific date and time
  • Using crontab is the same as you would use the 'vi' editor
  • Usage :
  • Edit cron jobs :
    • # crontab -e
       
  • List cron jobs for current logged in user :
  • # crontab -l
  • # crontab -l -u username
Note: Replace 'username' with corresponding user.
  • # crontab -r
  • # crontab -r -u username
Note: Replace 'username' with corresponding user.
  • List cron jobs for a different user :
  • Remove cron jobs for current logged in user :
  • Remove cron jobs for a different user :
  • M H D Mo W /path/to/script
    • M = Minute (00 to 59)
    • H = Hour (00 to 23)
    • D = Day of month (01 to 31)
    • Mo = Month (01 to 12)
    • W = Day of week (0 to 6 .. 0 = Sunday)
       
  • Use * to imply every hour, day, etc.
  • Example :
  • 30 02 15 6 * /root/scriptfile.sh
  • Executes '/root/scriptfile.sh' on June 15th at 2:30AM
  • 30 02 * * 0 /root/scriptfile.sh
  • Executes '/root/scriptfile.sh' every Sunday at 2:30AM
  • Example :
    • 30 02,14 15 6 * /root/scriptfile.sh
    • Executes '/root/scriptfile.sh' on June 15th at 2:30AM and 2:30PM
       
  • Example :
    • 30 02-05 * * 0 /root/scriptfile.sh
    • Executes '/root/scriptfile.sh' every Sunday at 2:30AM, 3:30AM, 4:30AM, and 5:30AM
       
  • @yearly - execute script every year
  • @monthly - execute script every month
  • @weekly - execute script every week
  • @daily - execute script every day
  • @hourly - execute script every hour
  • @reboot - execute script every reboot
  • Use these variables instead of the M H D Mo W format
    • Example :
      • @monthly /root/scriptfile.sh
      • Executes '/root/scriptfile.sh' on the first day of every month
         
  • Example :
  • Use , for multiple hours, days, etc.
  • Use - to span hours, days, etc.
  • Additional variables :
  • Formatting entries :

 

 

Back to Top


Cause

-

Résolution

-

Produits concernés

Red Hat Enterprise Linux Version 6
Propriétés de l’article
Numéro d’article: 000177157
Type d’article: Solution
Dernière modification: 13 août 2024
Version:  7
Trouvez des réponses à vos questions auprès d’autres utilisateurs Dell
Services de support
Vérifiez si votre appareil est couvert par les services de support.