check-password.sh 864B

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. LOCATION=$1
  3. KEYWORD=$2
  4. OPTION=$3
  5. COMPARE=$4
  6. CONDITION=$5
  7. #Example:
  8. #LOCATION="/etc/pam.d/common-password"
  9. #For debian is common-password ,for Gentoo and Red hat the file is system-auth
  10. #KEYWORD="pam_cracklib.so"
  11. #OPTION="ocredit"
  12. #COMPARE="gt"
  13. #CONDITION="-1"
  14. if [ -f "$LOCATION" ];then
  15. RESULT=$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' $LOCATION | grep "$KEYWORD.*$OPTION")
  16. #above line is remove any comment in the configuration file and use grep to output a exit status
  17. #if matched both $KEYWORD and $OPTION there is a success exit status: 0
  18. if [ $? -eq 0 ];then
  19. if [ "$(echo $RESULT | tr "\t" "\n" | tr " " "\n" | sed -n "/$OPTION/p"| awk -F "=" '{printf $2}')" -$(echo $COMPARE) "$CONDITION" ];then
  20. exit 1
  21. fi
  22. else
  23. exit 1
  24. fi
  25. fi