How to compare md5 hash values on a condition on shell script? -


question below code.

#!/bin/sh  check() {        dir="$1"     chsum1=`find ~/folder -type f -exec cat {} \; | md5`      chsum2=$chsum1      (( ; 0x$chsum1 == 0x$chsum2;  ))             echo "hello"         sleep 10         chsum2=`find ~/folder -type f -exec cat {} \; | md5`     done  echo "hello" #eval $2 }  check $* 

the goal is: make code works. does? applies md5 folder, compare md5 values. maintains loop until value different (that means on folder happened), after 10 secs when md5 calculates hash should different, code ends.

two questions.

  1. notice there commented while there. if uncomment while , comment for, notice code stops working. why? tried different combinations trying make work. enclosed quotes, used -eq, =, ==, etc. none worked. how make work whole?
  2. the way code now, if run output is:

((: d41d8cd98f00b204e9800998ecf8427e == 97329acaae00bdf66e30ac53b49e1036: value great base (error token "97329acaae00bdf66e30ac53b49e1036")

thus, how can fix second question , why happening. 

thank you!

the issue having (updated) posted code using for loop when while loop works.

the following code works me. changed for loop while loop.

#!/bin/sh  check() {         dir="$1"         chsum1=`find ~/nasatest -type f -exec cat {} \; | md5`         chsum2=$chsum1          while [ $chsum1 == $chsum2 ]                         echo "hello"                 sleep 10                 chsum2=`find ~/nasatest -type f -exec cat {} \; | md5`         done          echo "hello"         #eval $2 }  check $* 

the reason while loop wasn't working because missing spaces between square brackets , expression.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -