File: squid.cron.daily

package info (click to toggle)
squid 1.1.21-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 2,828 kB
  • ctags: 3,705
  • sloc: ansic: 34,400; sh: 1,975; perl: 899; makefile: 559
file content (81 lines) | stat: -rw-r--r-- 1,198 bytes parent folder | download | duplicates (2)
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
#! /bin/sh
#
# squid		Daily cron script for squid.
#
# Version:	@(#)squid.cron.daily  1.30  23-Oct-1997  miquels@cistron.nl
#

LOG_HISTORY=1

LOGDIR=/var/log/squid
cd $LOGDIR || exit 1

#
#	Gzip rotated logfiles, extensions 1 .. $LOG_HISTORY
#
zipit () {
	i=$LOG_HISTORY
	while [ $i -gt 1 ]
	do
		if [ -f $1.$i ]
		then
			gzip -9f $1.$i
		fi
		i=$[$i - 1]
	done
}

#
#	Rotate logfile(s).
#
rotate () {
	i=$LOG_HISTORY
	while [ $i -ge 0 ]
	do
		if [ -f $1.$i ]
		then
			mv -f $1.$i $1.$[$i + 1]
		fi
		if [ -f $1.$i.gz ]
		then
			mv -f $1.$i.gz $1.$[$i + 1].gz
		fi
		i=$[$i - 1]
	done
	[ -f $1 ] && mv $1 $1.0
}
 
#
#	See if squid rotates the logfile for us.
#
R=`grep '^logfile_rotate' /etc/squid.conf | sed 's/^.* //'`
if [ "$R" = 0 ]
then
	#
	#	Do rotate ourself.
	#
	for f in access.log cache.log hierarchy.log store.log useragent.log
	do
		[ -f $f ] && rotate $f
	done
fi

#
#	Now, let squid rotate or at least just flush the logfiles.
#
kill -USR1 `cat /var/run/squid.pid`
sleep 5

#
#	Gzip all logfiles with extension > .0
#
for f in access.log cache.log hierarchy.log store.log useragent.log
do
	zipit $f
done

#
#	Rotate the squid.out logfile
#
savelog -c 3 squid.out > /dev/null 2>&1