Version 1 – ping

This is something we can all do, as no special services are required. This will simplify the ping command for console users who may not know the details of the command. This will ping the server for just three counts rather than the normal infinite amount. There is no output if the server is alive, but a failed server reports sever dead. Create the following script as $HOME/bin/ping_server.sh:

#!/bin/bash# Author: @theurbanpenguin# Web: www.theurbapenguin.com# Script to ping a server# Last Edited: July 4 2015read -p "Which server should be pinged " server_addrping -c3 $server_addr 2>1 > /dev/null || echo "Server Dead"

The following screenshot shows successful and failed outputs:

Get Mastering Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.