Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Simple Network Ping Tool with Shell and HTML

In this article we will create a simple shell script to allow you to ping the network nodes and store the results as html file for printing, storage and proof.

In this article we are going to see how we can create a simple linux script that we can use to ping network nodes and print the results from HTML file. We will use shell as the scripting language.

We will achieve the printable ping results by specifying the name of the HTML file to output the results to, its structure and populating it with the results.

Using any text editor such as gedit or vi for coding, First lets indicate what linux interpreter should run our script, for our script we will use shell interpreter.

The code structure for our program is as follow:

 #!/bin/sh

As indicated the results will go to an HTML file, we first remove any pingresult.html file that may be there by:

rm pingresult.html

We recreate pingresult.html and add the opening HTML tag by using redirection, that is sending the results of the command to a file, you redirect by ">> pingresult.html" after the command.

echo '<html>' >> pingresult.html 

Now we format the heading of the report and the date that will be added later on, by centering and using heading 1 style.

echo '<center> <h1>' >> pingresult.html 

Then the heading of the server we are pinging is added below, here we pinging Google.

echo 'Google Ping Results</br>' >> pingresult.html 

Now lets add the date to script and make it italic in addition to the heading 1 style.

	echo '<italic>' >> pingresult.html 
	date >> pingresult.html 

The text formating closing tags:

	echo '</italic>' >> pingresult.html 
	echo '</br>' >> pingresult.html 
	echo '</h1> </center>' >> pingresult.html 

We will ping the server 3 times, in linux you have to control the ping iteration as it it does not terminate automatically. We use the ping flag -c for count and 1 to indicate a single ping attempt, the results will be also be written to the pingresult.html

	
        ping -c 1 www.google.com >> pingresult.html 
	echo '</br>' >> pingresult.html 
	ping -c 1 www.google.com >> pingresult.html 
	echo '</br>' >> pingresult.html 
	ping -c 1 www.google.com >> pingresult.html 
	echo '</br>' >> pingresult.html
	echo '</html>' >> pingresult.html

Save the file with .sh extension, give it executable rights and run it on any linux box.

The ping results on a browser

Figure1. The ping results on a browser.

The complete script is as follow:

        #!/bin/sh
	rm pingresult.html
	echo '<html>' >> pingresult.html 
	echo '<center> <h1>' >> pingresult.html 
	echo 'Google Ping Results </br>' >> pingresult.html 
	echo '<italic>' >> pingresult.html 
	date >> pingresult.html 
	echo '</italic>' >> pingresult.html 
	echo '</br>' >> pingresult.html 
	echo '</h1> </center>' >> pingresult.html 
	ping -c 1 www.google.com >> pingresult.html 
	echo '</br>' >> pingresult.html 
	ping -c 1 www.google.com >> pingresult.html 
	echo '</br>' >> pingresult.html 
	ping -c 1 www.google.com >> pingresult.html 
	echo '</br>' >> pingresult.html
	echo '</html>' >> pingresult.html



South African, complete 3 year IT Dimplma with Vaal University of Technology, Novell Certified Linux Admministrator 10.

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login