Search code examples
apachecroncentos6

restart apache service automatically using cron 12AM daily


I have a CentOs setup in test server.

I wanna to run a cron job (the cron needs to run apache server at 12AM) daily.

My cron.daily fodler is located in /etc/cron.daily

Please let me know the steps how to implement this.

Usually I use to restart the apache service using the below command:

service httpd restart

I wanna to do restart apache service automatically using cron 12AM daily.

Thanks in advance.


Solution

  • I got it and give you step by step adding cron jobs into your system:

    1. Login to your server with SSH
    2. Type crontab -l to display list of cron jobs,
    3. Type crontab -e to edit your crontab,
    4. Add 0 4 * * * /etc/init.d/mysqld restart to restart Mysql everyday at 4 AM,
    5. Add 0 5 * * * /etc/init.d/httpd restart to restart Apache everyday at 5 AM and
    6. Add 0 24 * * * /etc/init.d/httpd restart to restart Apache everyday at 12 AM
    7. Save your file,
    8. Recheck with crontab -l