225025 发表于 2018-8-19 12:48:01

shell 测试URL 是否正常脚本

# cat download.sh  
#!/bin/sh
  
[ -f /etc/init.d/functions ]&& . /etc/init.d/functions ##加载系统函数库
  
URL=$1##传参
  
DIR=$2
  
if [ $# -ne 2 ];then   #判断传参个数
  
   action "sh $0" /bin/false
  
echo "Warning:Lack parameter"
  
echo "USAGE: sh $0 WEB_URL DIR_PATH"
  
exit 1
  
fi
  
download(){##定义函数
  
if [ ! -d $DIR ];then
  
read -p "$DIR not exist need create?(y/n)" char #read读入
  
if [ "$char" = "y" ]   ##if判断 字符串比较“”双引号括起来 用=等号比较
  
   then               #整数比较 不用引号 可以用 -eq
  
   mkdir $DIR -p
  
   cd $DIR
  
   wget$URL&>/dev/null
  
       if [ $? -ne 0 ];then
  
       return "52"   #return 函数中的返回值,类似于exit
  
   fi
  
    else
  
   return "51"
  
   fi
  
fi
  
}
  
download$URL $DIR##前面download是函数名;$URL位置是函数的第一个参数,也是脚本的第一个参数=$1
  
if [ $? -eq 0 ];then
  
       action "wget $URL" /bin/true
  
       else
  
       sleep 1
  
       action "wget $URL" /bin/false
  
       sleep 1
  
       exit 1
  
   fi


页: [1]
查看完整版本: shell 测试URL 是否正常脚本