32bef4c42cae69c3434dd6a4f32714de6d40671f
[clinton/scripts.git] / apache-sync-logs
1 #!/bin/bash
2
3 # invoke this as root on mire
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
15 KEYTAB_DIR=/etc/keytabs/user.daemon
16 AFS_USER_DIR=/afs/hcoop.net/user
17
18 for A in $(find $LOCAL_LOG_DIR/user -mindepth 3 -maxdepth 3 -print); do
19 USER=`basename $A`
20 PATHBITS=`echo $USER | head -c 1`/`echo $USER | head -c 2`/$USER
21 LOG_SRC=$A/apache/log
22 LOG_DEST=$AFS_USER_DIR/$PATHBITS/logs/apache/
23 TMP_DEST=$LOG_SRC.tmp
24
25 if [ "$VERBOSE" = "true" ]; then
26 echo
27 echo "=============================================================================="
28 echo "syncing logs for $USER from $A"
29 echo " to $LOG_DEST ..."
30 fi
31
32 if [ ! -d "$LOG_DEST" ]; then
33 echo "Error: $LOG_DEST does not exist, please make it"
34 exit 1
35 else
36 rm -fr $TMP_DEST
37 cp -a $LOG_SRC $TMP_DEST
38 chown -R $USER $TMP_DEST
39 chmod -R u+rw $TMP_DEST
40 k5start -qtU -f $KEYTAB_DIR/$USER \
41 -- su $USER -c "rsync -a $TMP_DEST/ $LOG_DEST/"
42 rm -fr $TMP_DEST
43 [ "$VERBOSE" = "true" ] && echo " done."
44 exit 0
45 fi
46 done