DEV Community

Cover image for 1.Create a Cron Job
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

1.Create a Cron Job

Lab Information

The Nautilus system admins team has prepared scripts to automate several day-to-day tasks. They want them to be deployed on all app servers in Stratos DC on a set schedule. Before that they need to test similar functionality with a sample cron job. Therefore, perform the steps below:

a. Install cronie package on all Nautilus app servers and start crond service.

b. Add a cron */5 * * * * echo hello > /tmp/cron_text for root user.

Lab Solutions

🧭 Part 1: Lab Step-by-Step Guidelines

1️⃣ Login to Jump Host

ssh thor@jump_host.stratos.xfusioncorp.com

Password:

mjolnir123

Configure App Server 1

2️⃣ SSH to stapp01

ssh tony@stapp01

Password:

Ir0nM@n

3️⃣ Install cronie

sudo yum install -y cronie
Enter fullscreen mode Exit fullscreen mode

4️⃣ Start cron service

sudo systemctl start crond
sudo systemctl enable crond
Enter fullscreen mode Exit fullscreen mode

5️⃣ Add root cron job (FAST METHOD)

Instead of opening an editor, run:

echo "*/5 * * * * echo hello > /tmp/cron_text" | sudo crontab -
Enter fullscreen mode Exit fullscreen mode

Verify:

sudo crontab -l
Enter fullscreen mode Exit fullscreen mode

Expected:

*/5 * * * * echo hello > /tmp/cron_text

Configure App Server 2

SSH:

ssh steve@stapp02

Password:

Am3ric@

Run:

sudo yum install -y cronie
sudo systemctl start crond
echo "*/5 * * * * echo hello > /tmp/cron_text" | sudo crontab -
Enter fullscreen mode Exit fullscreen mode

Configure App Server 3

SSH:

ssh banner@stapp03

Password:

BigGr33n

Run:

sudo yum install -y cronie
sudo systemctl start crond
echo "*/5 * * * * echo hello > /tmp/cron_text" | sudo crontab -
Enter fullscreen mode Exit fullscreen mode

🧠 Part 2: Simple Explanation (Beginner Friendly)

What the lab is testing

The lab checks if you understand:

1️⃣ Installing cron
2️⃣ Running cron service
3️⃣ Creating scheduled tasks

Why install cronie

Cron functionality comes from the cronie package.

Without it:

crond service does not exist

So we install it.

Why start crond

crond is the scheduler daemon.

Think of it like:

a clock that checks tasks every minute

Understanding the cron job

*/5 * * * * echo hello > /tmp/cron_text

This means:

Every 5 minutes → run command

The command:

echo hello > /tmp/cron_text

Creates a file:

/tmp/cron_text

with content:

hello

Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)