Guest
Public paste!

BossaNesta

By: a guest | Nov 1st, 2009 | Syntax: Bash | Size: 1.35 KB | Hits: 178 | Expires: Never
Copy text to clipboard
  1. # show usage if '-h' or  '--help' is the first argument or no argument is given
  2. case $1 in
  3.         ""|"-h"|"--help") PrSyn ;;
  4. esac
  5.  
  6. # Define all acceptable variable names here
  7. ALL_OPT=(Type Host Pass User DB Table MaxTry BackupDir Src Dst Port sshUser Period dbExtra)
  8. Type="NULL"             # We are using $Type to do syntax check in the call up loop
  9. Period="daily"
  10.  
  11. for WORD in $@ ; do     # $WORD is the name of variable,
  12.   for OPT in ${ALL_OPT[*]} ; do         # Check if I have the option in the list
  13.   FIELDS=""
  14.   case $WORD in
  15.     $OPT=?*)  # To make sure it has '=' and at least one character after '='
  16.       FIELDS=${WORD:`echo ${#OPT}+1 |bc`}       # grap the value
  17.       eval $OPT=$FIELDS                         # Assign the variable to
  18.       echo "      export $OPT $FIELDS"
  19.       ;;
  20.     Report)
  21.       echo "calling up Report"
  22.       bkReport
  23.       break
  24.       ;;
  25.   esac
  26.   [ "$FIELDS" == "" ] || break          # no value at all
  27.   done
  28. done
  29.  
  30. # Display all variable names and value
  31. for OPT in ${ALL_OPT[*]} ; do
  32.     eval aaa=\$$OPT
  33.     echo $OPT = $aaa
  34. done
  35.  
  36. # Define all function names, which is the accepted variables value in first variable in ALL_OPT
  37. ALL_TYPE=(Mysql File MySql Redmine)
  38. [ $Type == "NULL" ] || for TypeCHK in ${ALL_TYPE[*]} ; do
  39.   if [ $Type == $TypeCHK ] ; then
  40.     ChkPeriod $Period
  41.     [ $? == 0 ] && bk$Type #echo -e "\n\n== Running... bk$Type $TypeCHK"
  42.   fi
  43. done