apache-sync-logs: Skip people who do not have keytabs
[clinton/scripts.git] / apache-sync-logs
CommitLineData
d2462e94 1#!/bin/bash
2
3# invoke this as root on mire
4
5exec 2>&1
6
7# drop any tokens; use only users' cgi tokens
b7036601 8kdestroy > /dev/null 2>&1
d2462e94 9unlog
10
b7036601 11#VERBOSE=true
12VERBOSE=false
13
d8d03ff4 14LOCAL_LOG_DIR=/var/log/apache2/user
b7036601 15KEYTAB_DIR=/etc/keytabs/user.daemon
16AFS_USER_DIR=/afs/hcoop.net/user
19b04bd3 17ERROR=no
b7036601 18
d8d03ff4 19# Sanify permissions so that we can safely create tmp directories and
20# run rsync.
21chmod -R u=rwX,g=rX,o=X $LOCAL_LOG_DIR
22
23# Iterate through logs for each user
24for A in $(find $LOCAL_LOG_DIR -mindepth 3 -maxdepth 3 -print); do
b7036601 25 USER=`basename $A`
26 PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER
6d0a0367 27 LOG_SRC=$A/apache/log
74c1bc9e 28 LOG_DEST=$AFS_USER_DIR/$PATHBITS/.logs/apache/
6d0a0367 29 TMP_DEST=$LOG_SRC.tmp
b7036601 30
be8e70a1 31 # Skip deleted or empty log directories
32 if test ! -d "$LOG_SRC" || ! ls "$LOG_SRC"/*/*/*.log >/dev/null 2>&1; then
33 continue
34 fi
35
c14f6fa4 36 # Skip people who do not have keytabs
37 if test ! -f "$KEYTAB_DIR/$USER"; then
38 continue
39 fi
40
be8e70a1 41 if test "$VERBOSE" = "true"; then
b7036601 42 echo
43 echo "=============================================================================="
44 echo "syncing logs for $USER from $A"
45 echo " to $LOG_DEST ..."
46 fi
47
be8e70a1 48 if test ! -d "$LOG_DEST"; then
b7036601 49 echo "Error: $LOG_DEST does not exist, please make it"
19b04bd3 50 ERROR=yes
b7036601 51 else
6d0a0367 52 rm -fr $TMP_DEST
40cee8c1 53 cp -r $LOG_SRC $TMP_DEST
d8d03ff4 54 chown -R $USER:nogroup $TMP_DEST
6b6c39d0 55 chmod -R u=rwX,go=X $TMP_DEST
b7036601 56 k5start -qtU -f $KEYTAB_DIR/$USER \
d8d03ff4 57 -- su $USER -c "rsync -a $TMP_DEST/ $LOG_DEST/"
6d0a0367 58 rm -fr $TMP_DEST
be8e70a1 59 test "$VERBOSE" = "true" && echo " done."
b7036601 60 fi
d2462e94 61done
19b04bd3 62
be8e70a1 63if test "$ERROR" = "yes"; then
19b04bd3 64 exit 1
65else
66 exit 0
67fi
68