need help with little bash server monitor script

hello,

i`m new in bash scripting and i getting an error with my little server monitoring script

example of my script:

#!/bin/sh
s1_ats=0


while [ 1 ]; do
sleep 5



s1=`ping -c 1 xxxx.xxxx.xxxx.xxxx | grep 64 | awk '{print $1}'`
if [ "$s1" == "64" ] ; then
  $s1_ats=0
  else
    if [ "$s1_ats" -ge "10" ] ; then
      echo -e "sms" >> /root/tikrinimas
      $s1_ats=0
      else
        let $s1_ats++
    fi
fi


done

i want to make, that 1 server pinging other servers and if ping fails x times it send`s to me an sms message. this echo -e "sms" >> /root/tikrinimas is for this time, later i`ll connect an gsm device and that device will send an mesage if ping fails 10 times

but im getting errors and i dont know why.

thanks for any help or comments

Hi grauzikas,

Welcome to the forum.
Can you please post the error messages?

i alredy remaked that script, and now my else wont work

#!/bin/sh
s1_ats=0


while [ 1 ]; do
sleep 1



s1=`ping -c 1 1.2.3.4 | grep 64 | awk '{print $1}'`
if [ "$s1" == "64" ] ; then
  s1_ats=0
  else
    if [ "$s1_ats" < "3" ] ; then
      let s1_ats++
      echo $s1_ats
      else
        echo -e "sms" >> /root/tikrinimas
        s1_ats=0

    fi
fi


done

output:

sh -x monitoringas
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'
+ s1=
+ '[' '' == 64 ']'
+ '[' 0 ']'
+ let s1_ats++
+ echo 1
1
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'
+ s1=
+ '[' '' == 64 ']'
+ '[' 1 ']'
+ let s1_ats++
+ echo 2
2
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'
+ s1=
+ '[' '' == 64 ']'
+ '[' 2 ']'
+ let s1_ats++
+ echo 3
3
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'
+ s1=
+ '[' '' == 64 ']'
+ '[' 3 ']'
+ let s1_ats++
+ echo 4
4
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'
+ s1=
+ '[' '' == 64 ']'
+ '[' 4 ']'
+ let s1_ats++
+ echo 5
5
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'

in this example if else worked then after 3 ping fails it mus set s1_ats to 0 and write sms into /root/tikrinimas file, but how can i see that else wont work

if i getting replays then everithing works ok

 sh -x monitoringas
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1
++ grep 64
++ awk '{print $1}'
++ ping -c 1 127.0.0.1
+ s1=64
+ '[' 64 == 64 ']'
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 127.0.0.1
++ grep 64
++ awk '{print $1}'
+ s1=64
+ '[' 64 == 64 ']'
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 127.0.0.1
++ grep 64
++ awk '{print $1}'
+ s1=64
+ '[' 64 == 64 ']'
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 127.0.0.1
++ grep 64
++ awk '{print $1}'
+ s1=64
+ '[' 64 == 64 ']'
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1