Pages

AIX Job Scheduler

In AIX, job schedulers are your secret weapon for automating repetitive or one-off tasks. From backups to reports to cleanup scripts, they reduce manual work and ensure consistency. Whether you rely on cron for recurring jobs or at for single-run tasks, mastering these tools is essential for any AIX administrator.

Let's break down how each works and share practical tips for reliability.

Cron (crontab): Perfect for Recurring Jobs
The cron daemon runs scheduled jobs repeatedly at defined intervals. Each user has a crontab file that specifies their job schedules.
Crontab Syntax:
Each line defines when and what to execute:
* * * * * command
- - - - -
| | | | |
| | | | ----- Day of week (0-7, Sunday=0 or 7)
| | | ------- Month (1-12)
| | --------- Day of month (1-31)
| ----------- Hour (0-23)
------------- Minute (0-59)

Example: Daily backup at 2:00 AM
0 2 * * * /home/user/backup.sh

Common Crontab Commands
CommandPurpose
crontab -eEdit your crontab
crontab -lList your crontab entries
crontab -rRemove your crontab
Multi-job Example:
30 1 * * 1 /home/user/weekly_report.sh    # Every Monday at 1:30 AM
0 0 1 * * /home/user/monthly_cleanup.sh   # First day of each month at midnight
System-wide job locations:
/var/spool/cron/crontabs/ (per-user)
/etc/cron.d/ and /etc/crontab

Pro Tip: Cron jobs run in a minimal environment—always use absolute paths in scripts.

At: Ideal for One-Time Jobs
While cron handles repeats, at schedules a job for a single execution at a specific time or date.
Scheduling with At
# at 14:30               # 2:30 PM today
# at now + 1 hour        # 1 hour from now
# at 23:00 09/30/2025    # 11:00 PM on Sep 30, 2025
After entering at, type commands, then press Ctrl+D:
at 14:30
> /home/user/script.sh
> <Ctrl+D>

Managing At Jobs
CommandPurpose
atqList pending jobs (shows job number, user, time)
atrm <job_number>Remove a scheduled job
Example:
# atq
1   user   2025-09-26 14:30 a
# atrm 1

Cron vs. At: Quick Comparison
FeatureCronAt
Job TypeRecurringOne-time
SchedulingMinute/Hour/DaySpecific time/date
StorageCrontab fileAt queue
Use CaseDaily backupsTomorrow’s report

Pro Tips for Reliable Scheduling

Use absolute paths (cron/at lack your full shell PATH):
0 2 * * * /home/user/backup.sh

Log output for debugging:
0 2 * * * /home/user/backup.sh > /tmp/backup.log 2>&1

Set execute permissions:
# chmod +x /home/user/backup.sh

Define PATH if needed:
PATH=/usr/bin:/usr/local/bin

Final Thoughts
Automating with cron and at transforms AIX system administration. Your backups, reports, and cleanups will run reliably, freeing you for strategic work.

Next Steps:
  • Combine cron and at for hybrid workflows
  • Monitor job logs regularly
  • Handle environment variables to dodge "works in terminal, fails in cron" issues
With these practices, your AIX scheduling will be rock-solid.

No comments:

Post a Comment