Day 6 of 100 Days of Devops
Create a Cron Job
The Requirement is as follow
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.
Install the Cron Job
As always we search the package make sure you have root access in order to make changes
1
2
3
4
5
6
7
8
9
[root@stapp01 ~]# yum search cronie
Last metadata expiration check: 92 days, 17:09:16 ago on Fri Aug 29 04:52:17 2025.
============================= Name Exactly Matched: cronie ==============================
cronie.x86_64 : Cron daemon for executing programs at set times
================================= Name Matched: cronie ==================================
cronie-anacron.x86_64 : Utility for running regular jobs
cronie-noanacron.x86_64 : Utility for running simple regular jobs in old cron style
Check the Cron service
1
[root@stapp01 ~]# systemctl status crond.service
Edit the Cron
Again help is always my go to option for me because we may forget the command , some how crontab does not complaint even if I type --help . I just want to see existing cron jobs if any and edit the cronttab.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@stapp01 ~]# crontab --help
crontab: invalid option -- '-'
crontab: usage error: unrecognized option
Usage:
crontab [options] file
crontab [options]
crontab -n [hostname]
Options:
-u <user> define user
-e edit user's crontab
-l list user's crontab
-r delete user's crontab
-i prompt before deleting
-n <host> set host in cluster to run users' crontabs
-c get host in cluster to run users' crontabs
-T <file> test a crontab file syntax
-s selinux context
-V print version and exit
-x <mask> enable debugging
Default operation is replace, per 1003.2
List existing crontab
You can use crontab -l for listing cronjobs. apparently there is no jobs for rootuser
1
2
[root@stapp01 ~]# crontab -l
no crontab for root
Editing the cronjob
You can edit edit using vi or using direct std out write to ` /var/spool/cron/yourusername` because cronjobs can be configured for different users.
Editing using crontab -e
1
crontab -e
Direct Std out to crontab file
1
echo "*/5 * * * * echo hello > /tmp/cron_text" >> /var/spool/cron/root
for more cron expression you may check your friend manual ` man 5 crontab
after editing you may restart the cron service.
1
systemctl status crond.service
Wait for 5 mins
Then check the file was written after 5 mins
1
2
[root@stapp01 ~]# cat /tmp/cron_text
hello
Thats all of today , Thx Bye !