File: cron.daily

package info (click to toggle)
apache 1.3.0-5
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 6,488 kB
  • ctags: 6,702
  • sloc: ansic: 47,562; sh: 3,221; makefile: 1,382; perl: 1,346; cpp: 55
file content (101 lines) | stat: -rw-r--r-- 2,307 bytes parent folder | download
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
#
# apache    Rotate the apache logfiles as specified in
#           /etc/apache/cron.conf
#
#           Johnie Ingram <johnie@debian.org>

[ -f /etc/apache/httpd.conf ] || exit 0

# DEFAULTS.  Override by editing /etc/apache/cron.conf.

APACHE_OLD_LOGS=35
APACHE_DAYS_TO_RUN=all
APACHE_DAY_TO_RUN=any
APACHE_POST_SCRIPT=

[ -f /etc/apache/cron.conf ] && . /etc/apache/cron.conf

umask 022

RUNTODAY=0

if [ "$APACHE_DAY_TO_RUN" = "any" ] ; then

    # Get today's day and convert to lowercase.
    TODAY=$(date +%a | tr 'A-Z' 'a-z')
    # Convert days_to_run to lowercase.
    APACHE_DAYS_TO_RUN=$(echo $APACHE_DAYS_TO_RUN | tr 'A-Z' 'a-z')
    echo "$APACHE_DAYS_TO_RUN" | grep -q "$TODAY" && RUNTODAY=1
    [ "$APACHE_DAYS_TO_RUN" = "all" ] && RUNTODAY=1

else

    # Get today's day: 01 .. 31
    TODAY=$(date +%d | cat)
    if [ $APACHE_DAY_TO_RUN = "$TODAY" ] ; then RUNTODAY=1; fi

    # Get today's day: 001 .. 366
    TODAY=$(date +%j | cat)
    if [ $APACHE_DAY_TO_RUN = "$TODAY" ] ; then RUNTODAY=1; fi

fi

if [ "$RUNTODAY" = "1" ] ; then

    # This looks for lines in the conf files like: FooLog /some/where
    LOGS=$(awk '$1 ~ /^[A-Za-z]*Log$/ && $2 ~ /^\// {print $2}' \
	/etc/apache/*.conf | sort -u)

    if [ "$LOGS" = "" ]
    then
	LOGS="/var/log/apache/access.log /var/log/apache/error.log"
	[ -d /var/log/apache ] || exit 0
    fi

    SERVERROOT=$(awk '$1 == "ServerRoot" { print $2; exit }' \
	/etc/apache/*.conf)
    if [ "$SERVERROOT" != "" ]
    then
	cd $SERVERROOT
    fi

    USR=$(awk '$1 == "User" { print $2; exit }' /etc/apache/*.conf)
    if [ "$USR" = "" ]
    then
	USR="root"
    fi

    GRP=$(awk '$1 == "Group" { print $2; exit }' /etc/apache/*.conf)
    if [ "$GRP" = "" ]
    then
	GRP="www-data"
    fi

    GRP=$(echo $GRP | sed "s/#//g")

    for LOG in $LOGS
    do
	if [ -f $LOG ]
	then
	    if [ "$APACHE_CHOWN_LOGFILES" = "1" ]
	    then
		savelog -c $APACHE_OLD_LOGS -m 664 -u $USR -g $GRP \
		    $LOG > /dev/null
	    else
		savelog -c $APACHE_OLD_LOGS -m 644 -u root -g root \
		$LOG > /dev/null
	    fi
	fi
    done

    # Send a reload signal to the apache server.
    /etc/init.d/apache reload > /dev/null

    # Run apache post processing script if executable.
    if [ -x "$APACHE_POST_SCRIPT" ]
    then
	$APACHE_POST_SCRIPT
    fi

fi