-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogalert.sh
More file actions
76 lines (69 loc) · 1.69 KB
/
logalert.sh
File metadata and controls
76 lines (69 loc) · 1.69 KB
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
#!/bin/bash
# Gaussian 16 log alert system
logchk=$1
foundwhen=$(date)
#Initial termlink
termlink=0
curllink=$(cat curllink.dat)
#########
# Default options
phonelink=0
debugger=0
#########
# Handle options
while getopts "p:d" option
do
case $option in
p ) phonelink=1 ;;
d ) debugger=1 ;;
\? ) echo "Invalid option -$option"; exit 1;;
esac
done
#Shift positional param
shift $(($OPTIND-1))
# This prevent it from infinitely running even when log is empty
if [ -z "$logchk" ]; then
echo "Log input is empty so program will exit now!"
return 1
fi
while [ $termlink = 0 ]; do
#Check for termination on last line only
if tail -n 1 $1 | grep -Fq "Normal termination"
then
#Program terminates normallyi
termlink=1
echo -e '\033[1;32mGaussian Normal Termination Alert\033[m'
echo "Found at $foundwhen checking process"
echo -e "\a"
if [ $phonelink = 1 ]; then
echo "Testphonelink = 1"
curl \
-H "Title: Gaussian Job Completed" \
-H "Priority: Default" \
-H "Tags: white_check_mark" \
-d "Normal termination of $1 on $(date), the job had had finished gracefully and will exit." \
$curllink
fi
elif grep -Fq "Error termination" $1
then
#Error termination
termlink=1
echo -e '\033[1;91mGaussian Error Termination Alert\033[m'
echo "Found at $foundwhen checking process"
echo -e "\a"
if [ $phonelink = 1 ]; then
curl \
-H "Title: Error Termination Alert" \
-H "Priority: Default" \
-H "Tags: warning,skull" \
-d "Error termination detected in $1 on $(date), please check the job or restart." \
$curllink
fi
else
sleep 60
#Want to loop this over
fi
done
if [ $debugger = 1 ]; then
echo "FOR DEBUGGING termination code : ${termlink}, phonelink: ${phonelink} connected to ${curllink}"
fi