Skip to content

Simple bash script for PING list of IP from a text file under linux.


The script and the text file containing the IPs must be in the same folder !

I use this script for ping a list of specific IP address that i keep in a text file. Feel free to use it, not perfect but it works and the job is done. Copy and paste the code in a text file named ping.sh and do :

chmod u+x ping.sh

Fill a text file with the IP you want to check like this, name it myaddresses.txt or what you want

192.168.2.1
192.168.2.15
192.168.2.33

After that you just have to :

./ping.sh myaddresses.txt

The script

#!/bin/sh
if [ -z $1 ]
then
        echo -e "\033[1;91mFile with IP is missing\033[0m";
        echo -e 'Example "./ping.sh \033[4;31mip.txt\033[0m"';
        exit 1;
fi
awk '{print $1}' < $1 | while read ip; do
    if ping -c 1 -W 0 $ip >/dev/null 2>&1; then
        echo -e "\033[4;32m$ip\033[0m \033[1;94mON LINE\033[0m"
    else
        echo -e "\033[4;31m$ip\033[0m \033[1;91mNOT ON LINE\033[0m"
    fi
done

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: