T. Collins
T. Collins

Reputation: 19

How do I fix “Syntax error near expected ‘fi’”

#!/bin/bash
HOSTS="cyberciti.biz theos.in router"
    
COUNT=4

for myHost in $HOSTS
do
  count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
  if [ $count -eq 0 ]; then
    # 100% failed 
    echo "Host : $myHost is down (ping failed) at $(date)"
  fi
done

Upvotes: 0

Views: 95

Answers (1)

Dominique
Dominique

Reputation: 17543

I've added some double quotes, this should do the trick:

#!/bin/bash
HOSTS="cyberciti.biz theos.in router"

COUNT=4

for myHost in $HOSTS
do
  count=$(ping -c $COUNT "$myHost" | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
  if [ "$count" -eq "0" ]; then
    # 100% failed 
    echo "Host : $myHost is down (ping failed) at $(date)"
  fi
done

Upvotes: 1

Related Questions