i made now a lot of shell scripting on my raspberry.
now there is one script i am stuck, the plan is to check a GPIO input and if the state changed, it sends a email.
but as soon the script is running, it sends every second a email, no matter what the input state is.
btw, the echos shows only once up and seems to work.
thanks for helping me...
Code: Select all
#!/bin/bash
echo "input3.sh written by Jason, all rights reserved"
echo "this scripts reads the input 2 of PiFace and sends an email if needed"
#Pin1
# Den Zustand des Eingangs lesen
previous=$(gpio -p read 203)
# Endlose Schleife
while true
do
# Den Zustand des Eingangs lesen
pin=$(gpio -p read 203)
# Wenn der Zustand geändert hat
if [ $pin -ne $previous ]
then
if [ $pin -lt $previous ]
then
# Eingeschaltet
echo "Input 3 true"
sleep 0.1
echo "sending mail..."
sendmail -v mail@mail.com < /var/www/mails/error.mail
else
# Ausgeschaltet
echo "Input 3 false"
fi
fi
previous=$pin
sleep 1
done