标签:os 文件 for ar log res ad app
断断续续 的写shell 老是忘记,现在把写过的传上来 ,好复习
# /bin/bash usage(){ echo "usage : `basename $0` 11111111111111111111111 11" } #echo $# LOGDIR="" if [ $# != 2 ];then usage exit 1 fi #cha xun can shu ru kahao zhongduan hao GREPPARAM=$1 #echo $2 DAY=$2 #echo $DAY DAYARRAY=(01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #echo ${DAYARRAY[3]} for DATA in ${DAYARRAY[@]} do #echo ${DATA} if [ "$DAY" == "${DATA}" ]; then echo "===right day========" flag="00" #else #echo "+++++ +++++" fi done echo $flag if [ "$flag" != "00" ];then echo "the second param is not right,please input the second param in 01 02 03 04 ......31" exit 1 elif [ "$flag" == "00" ];then # echo "the second param is right": IPADDRESS="`hostname -i`" echo $IPADDRESS case $IPADDRESS in 192.168.40.12) LOGDIR="/wls/applogs/rtlog/payadmSF001/trc/" ;; 192.168.40.13) LOGDIR="/wls/applogs/rtlog/payadmSF002/trc/" ;; 192.168.41.130) LOGDIR="/wls/applogs/rtlog/payadmSF003/trc/" ;; 192.168.41.131) LOGDIR="/wls/applogs/rtlog/payadmSF004/trc/" ;; 192.168.40.10) LOGDIR="/wls/applogs/rtlog/pospadmSF001/trc/" ;; 192.168.40.11) LOGDIR="/wls/applogs/rtlog/pospadmSF002/trc/" ;; *) echo "zhu ji bu dui, bu zhun fang weng" exit 1 ;; esac else exit 1 fi DAYLOGDIR=${LOGDIR}${DAY} echo $DAYLOGDIR find $DAYLOGDIR -mtime -4 |xargs grep -l $GREPPARAM
函数 shell 函数与其他程序语言不同,就算传参数到函数,函数定义时 也不需要再()里加参数
hostname -i 应该是根据登录用户的 主机名 在/etc/hosts 文件里找对应的IP
标签:os 文件 for ar log res ad app
原文地址:http://my.oschina.net/u/234018/blog/300362