[SOLVED] Help with bash script

A place for discussion of topics that are not specific to ZoneMinder. This could include Linux, Video4Linux, CCTV cameras or any other topic.
Post Reply
sime
Posts: 26
Joined: Thu Jan 01, 2015 8:45 pm

[SOLVED] Help with bash script

Post by sime »

Hi folks!
I succeded at using cron for changing ZM states (monitor & modect) depending of the time... In the morning, it sets modect and if the afternoon sets monitor.

The next step i want to do, is a bash script to see if me or my Gf are present in the house to set monitor so that we dont have any fals alarm.

To do it, il'l try to use the wifi of our cellphones.

Both cellphone get their specific IP address from DHCP in my router.
i want to ping them each 15 minutes to see if we are there..
I surely suck at bash and if anybody wants to correct my script...
the pings are ok but the echo in the IF zone dont work...
When it will be working, i'll just change the echo to /usr/local/bin/zmpkg.pl STATE

Code: Select all

#!/bin/bash
#Script pour détection de proximité
((count1 = 3))                            # Nombre de ping echoué max
while [[ $count1 -ne 0 ]] ; do
    ping -c 1 192.168.1.21                 # Premier essaie
    simon=$?
    if [[ $simon -eq 0 ]] ; then
        ((count1 = 1))                      # Si ca marche, sortir sans essayer plus loin
    fi
    ((count1 = count1 - 1))                  # Diminution des essaies
done

((count2 = 3))                            # Nombre de ping echoué max
while [[ $count2 -ne 0 ]] ; do
    ping -c 1 192.168.1.20                 # Premier essaie
    sandra=$?
    if [[ $sandra -eq 0 ]] ; then
        ((count2 = 1))                      # Si ca marche, sortir sans essayer plus loin
    fi
    ((count2 = count2 - 1))                  # Diminution des essaies
done

if [[ $simon -eq 0 && $sandra -eq 0 ]] ; then                  # Test d'output
    echo "Simon et Sandra sont la"
fi

if [[ $simon -eq 0 && $sandra -eq 2 ]] ; then                  # Test d'output
    echo "Simon est la, Sandra est pas la"
fi

if [[ $simon -eq 2 && $sandra -eq 0 ]] ; then                  # Test d'output
    echo "Sandra est la, Simon est pas la"
fi

if [[ $simon -eq 2 && $sandra -eq 2 ]] ; then                  # Test d'output
    echo "Personne a la maison"
fi
Thank you for your help

Simon
Last edited by sime on Tue Mar 24, 2015 1:35 pm, edited 2 times in total.
sime
Posts: 26
Joined: Thu Jan 01, 2015 8:45 pm

Re: Help with bash script

Post by sime »

ahhh, i fixed it,

ping exit code is 0 for succes an 1 for host unreachable..

exit code 2 is for other errors...

Can't wait to try this :) I just hope the cellphone will reply to ping event if idling...
Post Reply