check-login-defs.sh 663B

123456789101112131415161718192021
  1. #!/bin/bash
  2. LOCATION=$1
  3. KEYWORD=$2
  4. OPTION=$3
  5. if [ -f "$LOCATION" ];then
  6. RESULT=$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' $LOCATION | grep "$KEYWORD.*$OPTION")
  7. #above line is remove any comment in the configuration file and use grep to output a exit status
  8. #if matched both $KEYWORD and $OPTION there is a success exit status: 0
  9. if [ $? -eq 0 ];then
  10. if [ "$(echo $RESULT | tr "\t" "\n" | tr " " "\n" | sed -n "/$OPTION/p"| awk -F "=" '{printf $2}')" -$(echo $COMPARE) "$CONDITION" ];then
  11. exit 1
  12. fi
  13. else
  14. exit 1
  15. fi
  16. fi