In this post, I am going to show you how to create a cron job.
Create a cron job Kodekloud Task details:
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.
Important Note: Perform the below commands based on your question. The server, user name & other details might differ. So please read the task carefully before executing it.
Solution:- To create a cron job follow the steps below:
Step 1: To start with login to App Server 1
$ ssh tony@stapp01
Enter the password provided to you using the documentation for authentication.
Step 2: Switch to root user
$ sudo su -
Enter the password to authenticate to the root user.
Step 3: Install cronie package on the server
# yum install cronie -y
Step 4: Enable and Start cron service and check the status if it is started.
# systemctl enable crond
# systemctl start crond
# systemctl status crond
Step 5: Create a cronjob as per the task for the root user. Paste the (*/5 * * * * echo hello > /tmp/cron_text) and save it.
# crontab -e
Step 6: After adding the corn check the corn job for the root user with the below command:
# crontab -l
Important: You have to do this in all app servers stapp01, stapp02, stapp03. Here I have done it only on app server 1. Follow the same steps in all other app servers.
Once done on all 3 servers click on submit and finish the task.
Happy Learning!!
Check out other KodeKloud Engineer Tasks