Silence apache-sync-logs
[hcoop/scripts.git] / apache-sync-logs
1 #!/bin/bash
2
3 # invoked by cron as root on each web node
4
5 exec 2>&1
6
7 # drop any tokens; use only users' cgi tokens
8 kdestroy > /dev/null 2>&1
9 unlog
10
11 #VERBOSE=true
12 VERBOSE=false
13
14 LOCAL_LOG_DIR=/var/log/apache2/user
15 KEYTAB_DIR=/etc/keytabs/user.daemon
16 AFS_USER_DIR=/afs/hcoop.net/user
17 ERROR=no
18
19 # Iterate through logs for each user
20 for A in $(find $LOCAL_LOG_DIR -mindepth 3 -maxdepth 3 -print); do
21 USER=`basename $A`
22 PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER
23 USER_HOME=$AFS_USER_DIR/$PATHBITS
24 LOG_SRC=$A/apache/log/$(hostname)
25 LOG_DEST=$USER_HOME/.logs/apache/$(hostname)
26
27 # Skip deleted or empty log directories
28 # Possible inefficiency? (ls entire directory*400+ dirs)
29 if test ! -d "$LOG_SRC" || ! ls "$LOG_SRC"/*/*.log >/dev/null 2>&1; then
30 if test "$VERBOSE" = "true"; then
31 echo "Skipping $USER (deleted or empty log dir $LOG_SRC)"
32 fi
33 continue
34 fi
35
36 # Skip people who have unreadable log subdirectories
37 # This test is broken! --clinton
38 if test -d "$USER_HOME/.logs" && \
39 ! ls "$USER_HOME/.logs" >/dev/null 2>&1; then
40 if test "$VERBOSE" = "true"; then
41 echo "Skipping $USER (unreadable log dir $USER_HOME/.logs)"
42 fi
43 continue
44 fi
45
46 # Skip people who do not have keytabs
47 if test ! -f "$KEYTAB_DIR/$USER"; then
48 if test "$VERBOSE" = "true"; then
49 echo "Skipping $USER (missing keytab $KEYTAB_DIR/$USER)"
50 fi
51 continue
52 fi
53
54 if test "$VERBOSE" = "true"; then
55 echo
56 echo "=============================================================================="
57 echo "syncing logs for $USER from $LOG_SRC"
58 echo " to $LOG_DEST ..."
59 fi
60
61 if test ! -d "$USER_HOME/.logs/apache"; then
62 echo "Error: $USER_HOME/.logs/apache does not exist, please make it"
63 # ERROR=yes
64 # We will assume that people know what they are doing when they
65 # delete their ~/.logs/apache directory ....
66 # This is perhaps a bad assumption --clinton
67 if test "$VERBOSE" = "true"; then
68 echo "Skipping $USER (no $LOG_DEST directory)"
69 fi
70 continue
71 else
72 k5start -qtU -f $KEYTAB_DIR/$USER -- rsync -a --no-owner --no-group --delete $LOG_SRC/ $LOG_DEST/
73 test "$VERBOSE" = "true" && echo " done."
74 fi
75 done
76
77 if test "$ERROR" = "yes"; then
78 exit 1
79 else
80 exit 0
81 fi
82