Kenae
Kenae

Reputation: 59

Bash script Illegal number error

I'm trying to code some program to detect a video freeze on a RaspberryPi and I'm having trouble on my bash script. Here is what I've done to compare two screenshots in order to detect the freeze :

    #!bin/bash

    while true
    do
         sudo rm -rf /home/pi/shots/*
         sudo raspi2png -p /home/pi/shots/screen1.png -d 5
         sudo raspi2png -p /home/pi/shots/screen2.png -d 5
         ndiff=`compare -metric AE /home/pi/shots/screen1.png /home/pi/shots/screen1.png null:`
         if [ "$ndiff" -lt "100" ] ;
         then
                 sudo reboot
         fi
     done

I followed those intructions : Compare 2 images and find % difference but I think the illegal number comes from ndiff, can you please tell me what can I do ? Thanks

Upvotes: 0

Views: 789

Answers (1)

sjsam
sjsam

Reputation: 21965

Use diff instead of compare :

   dif=$(diff /home/pi/shots/screen1.png /home/pi/shots/screen1.png)    
#if the two files are exactly the same the $dif will be empty    
if [ -z "$dif" ] #checking if  $dif is empty or unset
then
   sudo reboot
fi

Or perhaps try this method.

Upvotes: 2

Related Questions