I have the following script

while read -r line
    ping_stat=$(ping -c 4 $name 2>&1)
        if [ $? -ne 0 ]
            echo "server $name is down"
            echo "server $name is up and running"
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

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.