Day 11 of 90 Days of DevOps Challenge: Automating Tasks with Cron Jobs and Process Management in Linux


In the world of DevOps and Linux system administration, automation is everything. Whether taking regular backups, deleting temp files, or running system health checks, Cron Jobs make it easy to schedule and execute tasks automatically. In this blog, we’ll dive deep into:
What are Cron Jobs?
Understanding cron (cron daemon)
Using crontab to manage cron jobs
Cron syntax and examples
Process management essentials
What is Scheduling in Linux?
Scheduling in Linux refers to setting up automated execution of tasks at specific times or intervals. It’s like setting an alarm to remind your system to do something except the system just does it for you without any reminder.
This is mainly done using a tool called cron.
What are Cron Jobs?
Cron Jobs are scheduled commands or scripts that are executed at a specified time or interval using the cron daemon.
Common Use Cases
Deleting temporary files
Running system updates
Sending email alerts
System health checks
Backing up databases
Scheduling reports
Cron Job Syntax
* * * * * <command_or_script>
│ │ │ │ │
│ │ │ │ └─ Day of the week (0-6) → Sun=0
│ │ │ └─── Month (1-12)
│ │ └───── Day of the month (1-31)
│ └─────── Hour (0-23)
└───────── Minute (0-59)
NOTE: No spaces around *
and always use absolute paths in commands.
Cron Job Examples
Schedule | Syntax |
Every 15 minutes | */15 * * * * /path/ script.sh |
Every day at 9:00 AM | 0 9 * * * /path/ script.sh |
Every day at 9:00 PM | 0 21 * * * /path/ script.sh |
1st day of every month at 10:30 AM | 30 10 1 * * /path/ script.sh |
Once on 28 Aug at 12:45 PM | 45 12 28 8 * /path/ script.sh |
What is crond
?
The crond
is a daemon process that runs in the background, it checks every minute if any job is scheduled and triggers it if scheduled.
What is a Daemon?
A daemon is a background process that runs continuously, usually started at boot time. It waits for specific events (in this case, scheduled times) to perform its function.
Key Points:
Starts at system boot (or manually via systemctl)
Checks cron job schedules every minute
Executes jobs defined in crontab files
Handles both system-wide and user-level cron jobs
Managing crond
with systemd
sudo systemctl start crond # Start crond
sudo systemctl enable crond # Enable on boot
sudo systemctl status crond # Check status
sudo systemctl stop crond # Stop the service
What is crontab
?
Crontab stands for cron table, it is a configuration file and command-line utility used to define and manage cron jobs (automated tasks) for each user in a Unix/Linux system.
Crontab = Schedule + Script + Time
The crontab file tells the crond daemon:
Which command to run
At what time to run it
How often to repeat it
Types of Crontabs
Type | Location | Purpose |
System crontab | /etc/crontab | Jobs for the whole system |
User crontabs | /var/spool/cron/ | Jobs specific to each user |
Crontab Commands
Command | Description |
crontab -e | Edit the current user's crontab file |
crontab -l | List current user's cron jobs |
crontab -r | Remove current user's crontab |
crontab -u <user> | Manage another user’s crontab (sudo) |
Cron Logs and Monitoring
Check if your job ran successfully by inspecting logs:
tail -f /var/log/cron # RHEL/CentOS
tail -f /var/log/syslog # Ubuntu/Debian
journalctl -u crond # Systemd journal logs
Process Management in Linux
In Linux, everything you run is a process. whether it's a script, command, background job, or system daemon. Process Management is the skill of monitoring, controlling, and terminating these processes as needed.
What is a Process?
A process is an instance of a program in execution. Every process has:
A unique process ID (PID)
A parent process (PPID)
A user who owns it
A state (running, sleeping, zombie, etc.)
Understanding Process Details
Field | Description |
PID | Process ID |
USER | Owner of the process |
%CPU / %MEM | CPU / Memory usage |
STAT | Process status (R, S, Z, T, etc.) |
TIME | CPU time used |
COMMAND | The command or script |
Process States
Code | Meaning |
R | Running |
S | Sleeping |
D | Uninterruptible |
T | Stopped |
Z | Zombie |
X | Dead |
Foreground vs Background Jobs
Foreground:
Runs in the terminal and blocks it until finished.
./script.sh
Background:
Runs in background, terminal remains free.
./script.sh &
Managing Background Jobs
Command | Description |
jobs | List background jobs |
bg %1 | Resume job in background |
fg %1 | Bring job to foreground |
ctrl+z | Suspend a foreground job |
Viewing Processes
ps # Current shell processes
ps aux # All running processes with details
ps -ef # Full format listing (commonly used)
top # Real-time view of CPU, memory, and processes
htop # Enhanced version (install separately)
Killing a Process
kill <PID> # Kill by Process ID
kill -9 <PID> # Force kill
pkill <process_name> # Kill by name
killall process_name # Terminates all processes by name
Checking Background Jobs
jobs # Show background jobs
bg %1 # Resume job in background
fg %1 # Bring job to foreground
ctrl +z # Suspend a foreground job
Final Thoughts
With cronjob scheduling and process management, I've mastered two essential pillars of automation in Linux. From timed backups to monitoring and managing system tasks, I’m now equipped to handle real-world DevOps scenarios. This also wraps up our Linux and Shell Scripting module.
The #90DaysOfDevOpsChallenge is progressing steadily, with consistent learning and blogging along the way. Let’s keep up the momentum and dive deeper into tools, pipelines, and cloud technologies next!
Subscribe to my newsletter
Read articles from Vaishnavi D directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
