Operations 8 min read

Master Linux Startup and Scheduling: chkconfig, rc.local, at & crontab Explained

This guide explains how to automate Linux tasks by configuring boot‑time services with chkconfig and rc.local, using the at command for one‑off jobs, and setting up recurring jobs with crontab, complete with syntax, examples, and practical shell script integration.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Startup and Scheduling: chkconfig, rc.local, at & crontab Explained

Why Automate?

Automation saves manpower, runs tasks during low‑traffic periods, reduces errors, and eliminates the need to manually repeat commands.

Boot‑time Startup

Many services need to start automatically when the system boots. The chkconfig command manages which services start at which runlevels.

Linux Runlevels

0 – Halt

1 – Single‑user mode

2 – Multi‑user, no NFS

3 – Multi‑user with NFS

4 – Unused

5 – Multi‑user with graphical interface

6 – Reboot

Common chkconfig commands:

chkconfig --list               # List current startup settings</code>
<code>chkconfig --add xxxd          # Add service xxxd to startup list</code>
<code>chkconfig [--level 1-6] xxxd on|off   # Enable/disable at specific levels</code>
<code>chkconfig --del xxxd         # Remove service from startup list

Editing rc.d Files

Directly edit files under /etc/rc.d/ (or /etc/rc.local) to customize boot actions, e.g., adding /usr/local/apache/bin/apachectl start to launch Apache on boot.

One‑Time Scheduling with at

The at utility runs a single command at a specified time.

# at 14:30               # Schedule a job at 14:30 today</code>
<code>at> /path/to/script.sh   # Enter the command to run</code>
<code>at> Ctrl+D               # Finish input

Common time specifications: at 09:00 tomorrow – 9 AM the next day at now + 30 minutes – 30 minutes from now at midnight – at midnight at 18:00 pm – 6 PM today

Note: the atd daemon may be disabled by default and must be started manually.

Recurring Scheduling with crontab

The cron daemon runs scheduled jobs defined in crontab files.

Configuration Files

/var/spool/cron/

– per‑user crontabs /etc/crontab – system‑wide jobs /etc/cron.d/ – additional crontab files

Directories /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly for scripts executed at those intervals.

Basic crontab Commands

crontab -e          # Edit current user's crontab</code>
<code>crontab -l          # List current crontab</code>
<code>crontab -r          # Remove current crontab

A crontab line consists of five time fields followed by the command. Supported symbols: * – every possible value / – step values (e.g., */5 every 5 units) - – range (e.g., 4-6 hours 4 to 6) , – list of values (e.g., 2,5 on Tuesdays and Fridays)

Example entries:

# 0 0 25 12 *      # Run at midnight on December 25</code>
<code>*/5 * * * *      # Every 5 minutes</code>
<code>* 4-6 * * *      # Every minute during 4 AM‑6 AM daily</code>
<code>* * * * 2,5      # Every minute on Tuesdays and Fridays

Using Shell Scripts with Cron

For complex logic, place commands in a shell script and invoke it from crontab.

#!/bin/sh

a="hello world"
echo $a

Then add to crontab, e.g., */5 * * * * /usr/sh/test.sh or run a PHP script: /phppath/php /filepath/test.php This runs the script every five minutes.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

automationLinuxSchedulingcronstartup
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.