写了两个脚本

第一次写脚本,写得很烂,不过还算成功了,以后的工作,只要是重复的,尽量写脚本完成,体力活让计算机去做,哈哈

参数主要有这么几个$1日期,$2文件类型,$3关键字

   getnum.sh

#用户统计远程服务器上的远程log的一些值
day=$1;
if [ "$day" == "" ]; then
        day=`date -d '1 days ago' +%Y-%m-%d`
fi
echo "Date:$day"
file=$2;
catfile="";
key="";
if [ "$file" == "share-video-pv" ];then
         file="/data/logs/share-video-pv.log";
         key="shareId:";
         catfile=$file-$day*;
fi
if [ "$file" == "share-pv" ];then
         file="/data/logs/share-pv.log";
         key="$3";
         catfile=${file}_${day};
fi
if [ "$file" == "share-create" ];then
         file="/data/logs/create/share-create.log";
         key="create type:$3";
         catfile=$file-$day*;
fi
total=0;
echo "catfile:$catfile"
server=/data/ugc/server/xnshare_server;
f_share_video_pv=/data/logs/share-video-pv.log;
path_video_pv=/data/wens/share-video-pv;
for ip in `cat $server`
do
   num=`ssh root@$ip "cat $catfile | grep '$key' | wc -l"`
   echo "$ip-$catfile: $num"
   total=`expr $total + $num`
done
echo "$day - $2 - get num total:$total"

    getfile.sh

#用来获得远程服务器上的文件
day=$1;
if [ "$day" == "" ]; then
        day=`date -d '1 days ago' +%Y-%m-%d`
fi
echo "Date:$day"
file=$2;
type="";
if [ "$file" == "share-video-pv" ];then
         file="/data/logs/share-video-pv.log";
         type="share-video";
fi
if [ "$file" == "share-pv" ];then
         file="/data/logs/share-pv.log";
         type="share-pv";
fi
if [ "$file" == "share-create" ];then
         file="/data/logs/create/share-create.log";
         type="share-create";
fi
echo "file:$file"
count=1;
skip=1;
server=/data/ugc/server/xnshare_server;
f_share_video_pv=/data/logs/share-video-pv.log;
path_video_pv=/data/wens/share-video-pv;
for ip in `cat $server`
do
  rm -rf $path_video_pv/$count/$day/$type;
  mkdir -p $path_video_pv/$count/$day/$type;
  `ssh root@$ip "scp $file-$day* [email protected]:$path_video_pv/$count/$day/$type"`
   count=`expr $count + $skip`;
done
 

猜你喜欢

转载自wensong.iteye.com/blog/939016