How to Install and Configure Cron Service on CentOS 6 Minimal (Missing crontab Command Fix)


3 views

When working with CentOS 6 minimal installations, you'll notice many common utilities aren't included by default. The cron service - essential for scheduling tasks - is one such package that requires manual installation.

# Verify if cron is installed
rpm -qa | grep cron

The cron service in CentOS 6 is provided by the vixie-cron package. Install it using yum:

# Install cron service
yum install -y vixie-cron

# Verify installation
rpm -qi vixie-cron

After installation, you need to start the crond service and configure it to launch at boot:

# Start the service immediately
service crond start

# Enable automatic startup on boot
chkconfig crond on

# Verify service status
service crond status

Now that cron is installed, here are some common usage patterns:

# Edit current user's crontab
crontab -e

# List scheduled jobs
crontab -l

# Remove all jobs
crontab -r

# Sample job running every day at 3am
0 3 * * * /path/to/your/script.sh

If you still encounter problems:

# Check cron package files
rpm -ql vixie-cron | grep crontab

# Verify PATH includes cron directories
echo $PATH

# Check for alternative cron implementations
yum search cron

For production systems, consider these security practices:

  • Restrict cron access via /etc/cron.allow and /etc/cron.deny
  • Always specify full paths in cron jobs
  • Log cron job outputs for monitoring
# Example secure cron entry with logging
0 * * * * /full/path/to/script.sh >> /var/log/cron.log 2>&1

On a fresh CentOS 6 minimal installation, you might encounter the frustrating crontab: command not found error. This happens because the minimal install doesn't include the cron service by default. Let's verify this:

# Check if crontab exists in PATH
which crontab
# Expected output: /usr/bin/which: no crontab in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)

# Check installed packages
rpm -qa | grep cron
# No output means cron isn't installed

The main cron package in CentOS 6 is cronie, which provides the Vixie cron implementation. Install it with:

yum install cronie
yum install cronie-anacron  # Optional: for systems that might be powered off

After installation, verify the packages and check crontab availability:

rpm -q cronie
# Should return package version like: cronie-1.4.4-16.el6.x86_64

which crontab
# Should now show: /usr/bin/crontab

CentOS 6 uses the older SysV init system. Start and enable the cron service:

service crond start
chkconfig crond on

Now that crontab is available, here are some common operations:

# Edit current user's crontab
crontab -e

# List current user's crontab
crontab -l

# Remove current user's crontab
crontab -r

Here are some practical examples of cron jobs you might want to set up:

# Run a script every day at 2:30 AM
30 2 * * * /path/to/script.sh

# Run a command every 5 minutes
*/5 * * * * /usr/bin/php /var/www/cron.php

# Run a backup script every Sunday at midnight
0 0 * * 0 /root/scripts/backup.sh

If cron jobs aren't running as expected:

  1. Check the cron log: tail -f /var/log/cron
  2. Verify the service is running: service crond status
  3. Ensure scripts have execute permissions: chmod +x script.sh
  4. Test commands manually before adding to cron

When setting up cron jobs:

  • Use absolute paths for commands and scripts
  • Consider using /etc/cron.allow to restrict cron access
  • Redirect output to log files for debugging
  • Set proper permissions on scripts (avoid world-writable)

Example with logging:

0 * * * * /path/to/script.sh > /var/log/script.log 2>&1