定時將應用日誌移動到指定目錄
阿新 • • 發佈:2018-01-04
pri gpo parameter $1 san sof 16px 定時同步 then
定時經日誌輸出到指定目錄,並打包
1 #!/bin/bash
2
3 backupLog()
4 {
5 FROMDIR=$1;
6 TODIR=$2;
7
8 if [[ -z "$FROMDIR" || -z "$TODIR" ]]; then
9 echo "parameter error!";
10 return;
11 fi
12
13 if [ ! -d $TODIR ]; then
14 mkdir -p $TODIR
15 fi
16
17 cd $FROMDIR
18 find . -name "*.log.*" | awk -F " " ‘{sub("./","");print $1}‘ | xargs -i cp "{} " $TODIR/{}
19 cd $TODIR
20 find . -name "*.log.????-??-??" -exec tar -zcf "{}.tar.gz" {} \;
21 find . -name "*.log.????-??-??" | awk -F / ‘{sub("./","");print}‘ | xargs rm -rf ;
22 }
23
24 GUANGSOFT=/opt/GuangheHome
25 LOGDIR=/opt/log
26
27 backupLog $GUANGSOFT/guanghe/logs $LOGDIR/guanghe
定時同步日誌到指定目錄
1 #!/bin/bash
2
3 transferLog()
4 {
5 FROMDIR=$1;
6 TODIR=$2;
7 FILES=$3;
8
9 if [[ -z "$FROMDIR" || -z "$TODIR" || ${#FILES[@]} -le 0 ]]; then
10 echo "parameter error!";
11 return;
12 fi
13
14 if [ ! -d $TODIR ]; then
15 mkdir -p $TODIR
16 fi
17
18 for VAR in ${FILES[*]}
19 do
20 cp -r $FROMDIR/$VAR $TODIR/$VAR
21 done
22
23 }
24
25 GUANGSOFT=/opt/GuangheHome
26 LOGDIR=/opt/log
27 FILES=(info.log debug.log error.log)
28
29 transferLog $GUANGSOFT/guanghe/logs $LOGDIR/guanghe $FILES
30
31
32
定時將應用日誌移動到指定目錄