Earlier, we created a script to restart the Apache web server HERE. Today we are going to add this to Cron so it restart every day a 3:00AM.
Here’s how to create a cron job for the
- Open the crontab file by running the following command in the terminal:
Add the following line to the file to schedule the script to run every day at 3 AM:
0 3 * * * /path/to/restart_apache.sh
Note: Replace “/path/to/restart_apache.sh” with the actual path to your
restart_apache.sh script file.
- Save the file and exit the text editor by pressing
Ctrl + X, then
Y, and finally
- The cron job is now set up to run the
restart_apache.shscript every day at 3 AM.
Note: To list the cron jobs for the current user, you can run the following command in the terminal:
To edit an existing cron job, simply open the crontab file using the
crontab -e command, make your changes, and save the file. To remove a cron job, delete the corresponding line from the crontab file and save the file.