sh kinit.sh#通信确认,避免每次输入密码
search_uid=$1; shift#参数处理
search_date=${1}; shift
search_time=${1}; shift
querytype=${1}; shift
server=${1}; shift
filename="oce_log."$search_date
#date格式为:year-month-day-hour,time格式为:hour-minute-second
querytime=`echo $search_date | sed 's/-/ /g'`#反引用符号,将结果赋值给变量querytime
date_arr=($querytime)
querytime=${date_arr[0]}${date_arr[1]}${date_arr[2]}${date_arr[3]}
localtime=`date +%Y%m%d%H`#大小写区别Y:2014,y:14
if [ $querytime = $localtime ]; then#shell中的if语句对空格要求比较高
filename="oce_log"
fi
if [ "$querytype" = "add" ]; then
match="Add"
elif [ $querytype = "show" ]; then
match="delete"
fi
ssh "$server" "cd /News0 && grep $match $filename | grep $search_uid > content "#进行远程连接,始终保持本地的方法
if [ $querytype = "add" ]; then
ssh "$server" " cd /News0 && cat content | awk '{for(i=1;i<=NF;i++) {if(!(i>=2 && i <= 6)) {printf(\"%s \", \$i);}} printf(\"\n\")}' "
elif [ $querytype = "show" ]; then
ssh "$server" " cd /News0 && cat content | awk '{for(i=1;i<=NF;i++) {if(i==1 || i==12 || i==15) {printf(\"%s \", \$i);}} printf(\"\n\")}' "
fi
#sh中写awk语句,要把$转义,NF表示字段的数目,NR表示行数
ssh "$server" "cd /News0 && rm -f content"
ssh "xce@10.x.x.x" "cd ~/h"