-
Notifications
You must be signed in to change notification settings - Fork 0
/
modified-files-check.sh
54 lines (43 loc) · 1.02 KB
/
modified-files-check.sh
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
#!/bin/bash
DAYSOLD=1
WWWDIR=/var/www
MODLOG=/var/log/modified-files.log
TMPLOG=/tmp/tmp-modified-time.log
EMAILMSG=/tmp/tmp-email-msg.txt
SUBJECT="FFXIAH.com - Modified File Log"
EMAILADDYS="[email protected] [email protected]"
touch $TMPLOG $EMAILMSG
# Clean email message file
echo -n '' > $EMAILMSG
# Check and validate tmptime
TMPTIME=$(head -n 1 $TMPLOG)
if [[ ! "$TMPTIME" =~ [0-9]+ ]] ; then
TMPTIME=0
fi
NEWEST=0
SEND=0
MODFILES=$(find $WWWDIR -mtime -$DAYSOLD | egrep 'html$|js$|php$|py$')
for modfile in $MODFILES
do
timestamp=$(ls -l --time-style="+%Y%m%d%H%M%S" $modfile | cut -f6 -d' ')
if [ $timestamp -gt $TMPTIME ] ; then
if [ $timestamp -gt $NEWEST ] ; then
NEWEST=$timestamp
fi
SEND=1
ls -l $modfile >> $EMAILMSG
ls -l $modfile >> $MODLOG
fi
done
# Update the tmp timestamp
if [ $NEWEST -gt $TMPTIME ] ; then
echo $NEWEST > $TMPLOG
fi
# Send any new files
if [ "$SEND" -eq 1 ] ; then
for email in $EMAILADDYS
do
/bin/mail -s "$SUBJECT" "$email" < $EMAILMSG
done
fi
echo -n '' > $EMAILMSG