In: Computer Science
Need to process these steps in UNIX.
To encourage users to get a good night's sleep, it has been decided that the web server will be unavailable from 23:30 each night until 07:00 the next morning.
Create a cron file named /etc/cron.d/web that stops httpd each evening at 23:30 and restarts it the next morning at 07:00.
Run the following command to create the file:
touch /etc/cron.d/web
Code to be written in this file:
#define the shell which will be used to run the commands
SHELL=/bin/bash
#defines the path of shell
PATH=/sbin:/bin:/usr/sbin:/usr/bin
#if you want to send the mail to user, set this property
MAILTO=""
#cronjob to stop the web server each night at 23:30
30 23 * * * root systemctl stop httpd
#cronjob to start the web server each morning at 07:00
00 07 * * * root systemctl start httpd
The first 5 parameters of the cron job are used to define the time when the cronjob would be run.
1st is for the minutes. 2nd is for the hours. 3rd is for the day of the month. 4th is for the month. 5th is for the day of the week. These must be followed by the command which needs to be run.
As we want our cronjob to run each day, we set the last three parameters as * which means for all the values of that parameter. For the first two, we define the minutes and hours.
Also, to stop or start the httpd service we require administrator access so we specify the keyword root before writing those commands to provide root access while running the job.