linux惯用验证

linux惯用验证

linux常用验证
#return 0 means input right, return 1 means input wrong
checkPort()
{
   #check the input number
 
   echo $1 | grep [^0-9] > /dev/null
   if [ $? = 0 ]
   then
     echo “please input number.”    
     return 1
   fi;
       
    echo $1 | grep ^[1-9] > /dev/null
    if [ $? != 0 ]
    then
        echo “the first number should not be 0.”
        return 1
    fi;
       
    if [ $1 -gt $maxNumberPort ]
    then
        echo “the max number of the port should not more then $maxNumberPort.”
        return 1
    fi;
   
    if [ ! -z $2 ]
    then
        lsof -i:”$1″ >>$log
        if [ $? -eq 0 ]
            then
    echo “The port $1 has been used, please input another. “
return  1
       fi
    fi;
  

    return 0
}

#return 0 means the path is ok, return 1 means the path has some errors
checkInstallPath()
{
        installMaxLength=255
        if [ $# != 1 ]
then
   echo “please check the input parameters”
   return 1
fi;

grep  ” ” $1
if [ $? = 0 ]; then
echo ” The install path can not contain bank .”
return 1
fi
       
echo “$installPath” | grep ‘[^-A-Za-z0-9._/]’ > /dev/null
        if [ “$?” = 0 ]; then
            echo
    echo -n “ISM cannot be installed in a directory containing special character in its name.”
    return 1;
fi

#deal with the relative path
#full path
firstChar=`echo “$1” | awk ‘{print substr($0,1,1)}’`
#if user input a relative path, then we will put “/” ahead of the path
if [ “$firstChar” != “/” ]; then
echo “please input full path!!”
return 1
fi

if [ ! -d $1 ]; then
            echo “please make sure the directory exist.”
    return 1
fi

#check the length of the path
declare -i length
length=`echo “$1” | wc -m`
length=length-1
if [ $length -gt $installMaxLength ]; then
    echo
    echo -n “the max length of The installation path is 255”
    return 1
fi
       
return 0
}

#return 0 means it is ok,return 1 means it has some formate error
checkIpAddress()
{

  if [ $# != 1 ]
  then
      echo “please check the input parameter!!”
      exit 1
  fi;

  ipSegLength=`echo $1 | awk -F [.] ‘{print NF}’ `

  if [ $ipSegLength != 4 ]
  then
      echo “ip formate error!!!”
      return 1
  fi;<br /

linux惯用验证

相关文章:

你感兴趣的文章:

标签云: