summaryrefstree
path: root/usr/bin/syslog_combine
blob: bd8359bf3730c3a5f28fdbe071d353a8b3a1eb07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh

SYSLOG_CONF_FILE=/etc/log_config/syslog.conf
DEST_PATH=/tmp
SOUR_PATH=/var/log

usage()
{
    cat <<EOF
Usage: syslog_combine [OPTION]

Known values for OPTION are:

  -c		combine the syslog files,the result in DEST_PATH 
  -r		remove combined files in DEST_PATH
EOF

    exit $1
}

do_combine()
{
	#debug
	#set -x
	fn=$1
	
	cnt=`ls $SOUR_PATH/$fn.* | wc -l`
	
	cf=$DEST_PATH/$1.combined
	
	#creat file
	echo > $cf

	while [ 0 -ne $cnt ]
	do
		if [ -e $SOUR_PATH/$fn.$cnt ] ; then
			echo $fn.$cnt >> $cf
			cat $SOUR_PATH/$fn.$cnt >> $cf	
		fi
		cnt=$(($cnt-1));
	done
	if [ -e $SOUR_PATH/$fn ] ; then
		echo $fn >> $cf		
		cat $SOUR_PATH/$fn >> $cf
	fi
}
do_rm_combined_log()
{
	rm $DEST_PATH/*log.combined
	#rm $SOUR_PATH/*log*
}

if [ "$1" = "-c" ]; then	
	cat $SYSLOG_CONF_FILE|
	while read line
	do
		file_name=`echo $line | awk -F "/" '{print $NF}'`
		echo $file_name
		do_combine $file_name
	done
	exit 1
fi

if [ "$1" = "-r" ]; then
	do_rm_combined_log
	exit 1
fi

input_param="-c -r"
for i in $input_param
do
	if [ ! "$1" = "$i" ]; then
		echo "input param $1 error!!!"
		usage
		else
		break
	fi
done