-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaccesslogs_hourly.sh
95 lines (82 loc) · 2.36 KB
/
accesslogs_hourly.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
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
#!/bin/bash
#Hourly access log roll-ups to Hive
jobName="Access Hourly"
processTimeFile="/home/user/states/access_hourly.state"
logFile="/home/user/logs/access_hourly.log"
email="[email protected]"
pigScript="/home/user/pig/accesslogs_hive_job_combined_hourly.pig"
function lockFile {
mv "$processTimeFile" "$processTimeFile.lock"
}
function unlockFile {
mv "$processTimeFile.lock" "$processTimeFile"
}
function checkProcessTime {
if [ -z "$processTime" ]; then
echo "The process time cannot be read, try $errorCounter." | mail -s "$jobName Job Time Corrupt" -r hosting-hadoop-noreply@`hostname -f` $email 2>> $logFile
return 1
else
return 0
fi
}
function readTimeFile {
if [ ! -f "$processTimeFile" ]; then
echo "Can not find $processTimeFile, try $errorCounter." | mail -s "$jobName Job State File Missing" -r hosting-hadoop-noreply@`hostname -f` $email 2>> $logFile
return 1
else
return 0
fi
}
function setProcessTime {
errorCounter=0
while [ $errorCounter -lt 7 ];
do
readTimeFile
if [ $? -eq 0 ]; then
processTime=$(date --date="$(cat $processTimeFile)" '+%Y-%m-%d %H:00 %z')
checkProcessTime
if [ $? -eq 0 ]; then
break
else
sleep 180
fi
else
sleep 180
fi
errorCounter=$[$errorCounter + 1]
done
if [ $errorCounter -lt 7 ]; then
return 0
else
return 1
fi
}
function runPigScript {
errorCounter=0
while [ $errorCounter -lt 7 ];
do
pig -stop_on_failure -useHCatalog -param PROCESSTIME="$processTime" $pigScript
if [ $? -eq 0 ]; then
processTime=$(date --date="$processTime 60 minutes" '+%Y-%m-%d %H:00 %z')
printf "$processTime\n" > "$processTimeFile.lock"
break
else
echo "The script did not process correctly for $processTime, try $errorCounter." | mail -s "$jobName Pig Script Update Failed" -r hosting-hadoop-noreply@`hostname -f` $email 2>> $logFile
sleep 180
fi
errorCounter=$[$errorCounter + 1]
done
if [ $errorCounter -lt 7 ]; then
return 0
else
return 1
fi
}
setProcessTime
if [ $? -eq 0 ]; then
lockFile
runPigScript
if [ $? -eq 0 ]; then
unlockFile
fi
fi