I am trying to get the number of hops using ping command I used a loop to repeat the command with incremental TTL values but I need to know when the ping succeeds and isn't a "TTL expired in transit" error
success=0
counter=1
while [ $success == 0 ]; do
echo TTL: $counter
ping -n 1 google.com -i $counter
res=$?
if [[ $res == 0 ]]; then
success=1
fi
((counter++))
done
echo $counter
You need something like this: