Skip to main content

Command Palette

Search for a command to run...

Day 6/100 of DevOps

Day 6: Create a Cron Job

Updated
•2 min read•View as Markdown

Task: 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.

Here, there are 3 applications. We need to make changes in all of these.

Steps:

  1. Connect to the target server (App Server)

    ssh tony@stapp03

  1. Switch to the root user for administrative privileges:

    sudo su - or sudo -i

  1. Install the cronie package (cron implementation)

    yum install cronie -y

  1. Start the Crond service and check the status

    systemctl start crond

    systemctl status crond

  1. Open the root user's crontab for editing

    sudo crontab -e

  1. Add the following line to the file

    /5 * echo hello > /tmp/cron_text

*/5: This specifies that the command should run every five minutes.

* * *: These asterisks represent the hour, day of the month, month, and day of the week, respectively, indicating that the job should run regardless of these values.

echo hello > /tmp/cron_text: This is the command to be executed, which writes "hello" into the file

/tmp/cron_text, overwriting its content each time.

Once Added, resrat the Crond service

systemctl restart crond

  1. Verify the changes

    After 5 minutes, I confirmed it worked by checking with:

    cat /tmp/cron_text