Question: Creating A Script For The Crontab | The Curl Command First create a directory within your home directory called logs. This is where we will

Creating A Script For The Crontab | The Curl Command

First create a directory within your home directory called logs. This is where we will save our outputted logs.

To get things going with log files and log rotations we will create a script in our home directory that will log its outcome. We will call this script IsTheServerUp.bash. As you may have guessed from its name, the script will check to see if a server is up. It will then log(echo) the outcome of the script to the file. We will be using the curl command to check to see if a server is up and running. The curl command is a command that connects to a url and transfers data from it. The data to transfer depends on how the command is ran but by default it will retrieve the HTML document of a web page. Use the following set of rules to write your bash script:

Use the curl command to request a web page from the server

e.g, curl http://www.csun.edu/ (You can use whatever webpage you want)

provide the --output /dev/null option + argument to suppress output

Check the return status ($?) to determine if there is a problem

If a status of 0 is returned, log to the file a message of success. If it is not a 0, log to the file a message of error. Make sure to include the status code and the date/time stamp. An example can look like so: (check date man page on how to format the date/time stamp) NOTE: Pay attention to date format

Apr-11-2015-04:12:00 PM (0) Web Server [ www.xbox.com ] Is Online Apr-11-2015-08:39:00 PM (7) Web Server [ www.xbox.com ] Is Offliline

Log your outputted messages to a file called Server_Info.log in your newly created logs directory. You can use whatever webpage you want

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!