0

I have the following script

filename="network_list.txt"
while read -r line
do
    name="$line"
    ping_stat=$(ping -c 4 $name 2>&1)
        if [ $? -ne 0 ]
        then 
            echo "server $name is down"
        else 
            echo "server $name is up and running"
        fi
done < "$filename"

But its output is unexpected and coming as "is up and running01" "is up and running02" .. network_list.txt file format is like

192.168.1.101
192.168.1.102
192.168.1.103
192.168.1.104
192.168.1.105

I just need to have a ping test on these serverss.

  • Sorry, but I can't reproduce your error with bash-4.3.43-4.fc25. It works fine in my case – Jaroslav Kucera Dec 5 '17 at 14:01
  • The script is working on centos 7 , but am working in ubuntu – Crazyrubixfan Dec 5 '17 at 14:20
  • Which Ubuntu version and which version of bash? – Jaroslav Kucera Dec 5 '17 at 14:37
  • ubuntu 12.04 and GNU bash, version 4.2.25(1)-release-(i686-pc-linux-gnu) – Crazyrubixfan Dec 5 '17 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.