server wake up time

Check if all your servers are up

I got a task to do. Every morning check if a cluster of servers is up and restart those, which aren’t. To check if a server is up we’d use:

ping -c 1 IP

which pings the server once.

Ok, that’s over. But like I said I got a list of servers, which changed every morning so it requires to write a simple script. I decided to use linux Bash scripting. Assuming the input data is a list of IPs in csv format, we may create a new file, let’s name it

chmod +x

and copy and paste this contents

# Program name:
# author: Picios
# Usage: ./ list.csv


while read p; 
	IPDIRTY=$(echo $p | tr '\r' ' ')
	IP=$(echo $IPDIRTY)
	ping -c 1 $IP &> /dev/null
	if [ $? -eq 0 ]; then
		echo "$IP		is up"
	   	echo "$IP		is down"
done <$FILE


IPDIRTY=$(echo $p | tr '\r' ' ')
IP=$(echo $IPDIRTY)

part is only to clean input line, because sometimes it happens to get some white spaces.

Hit ESCAPE and double SHIFT+Z to save file. Next create a list of servers you want to check. I won’t show you mine, but it would look like this:

Save to a file called eg. list.csv. And now run our test:

./ list.csv

You will get a nice list of servers. Use it well nerds.

One thought on “Check if all your servers are up

Comments are closed.