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

Vaishnavi DVaishnavi D
5 min read

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

ScheduleSyntax
Every 15 minutes*/15 * * * * /path/script.sh
Every day at 9:00 AM0 9 * * * /path/script.sh
Every day at 9:00 PM0 21 * * * /path/script.sh
1st day of every month at 10:30 AM30 10 1 * * /path/script.sh
Once on 28 Aug at 12:45 PM45 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

TypeLocationPurpose
System crontab/etc/crontabJobs for the whole system
User crontabs/var/spool/cron/Jobs specific to each user

Crontab Commands

CommandDescription
crontab -eEdit the current user's crontab file
crontab -lList current user's cron jobs
crontab -rRemove 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

FieldDescription
PIDProcess ID
USEROwner of the process
%CPU / %MEMCPU / Memory usage
STATProcess status (R, S, Z, T, etc.)
TIMECPU time used
COMMANDThe command or script

Process States

CodeMeaning
RRunning
SSleeping
DUninterruptible
TStopped
ZZombie
XDead

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

CommandDescription
jobsList background jobs
bg %1Resume job in background
fg %1Bring job to foreground
ctrl+zSuspend 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!

0
Subscribe to my newsletter

Read articles from Vaishnavi D directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vaishnavi D
Vaishnavi D