send notification by email when holiday CSV has been updated
This commit is contained in:
parent
f23cb44082
commit
04229e0527
13
update
13
update
@ -2,6 +2,10 @@
|
||||
|
||||
# Settings
|
||||
CSV_URL="https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv"
|
||||
MAIL_TO="$USER"
|
||||
MAIL_FROM="info@holiday.kareha.org"
|
||||
MAIL_SUBJECT="Holiday CSV Updated"
|
||||
MAIL_BODY="Holiday CSV file has been Updated."
|
||||
|
||||
# Constants
|
||||
EXIT_SUCCESS=0
|
||||
@ -18,6 +22,7 @@ verify_command() {
|
||||
verify_command "curl"
|
||||
verify_command "nkf"
|
||||
verify_command "awk"
|
||||
verify_command "mailx"
|
||||
|
||||
# Logging
|
||||
CURRENT_MONTH=$(date "+%Yw%U%z")
|
||||
@ -35,6 +40,13 @@ log() {
|
||||
echo "$timestamp $message" >>$LOG_FILE
|
||||
}
|
||||
|
||||
send_mail() {
|
||||
echo "$MAIL_BODY" | mailx -r "$MAIL_FROM" -s "$MAIL_SUBJECT" "$MAIL_TO"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "Failed to send email"
|
||||
fi
|
||||
}
|
||||
|
||||
# Acquire the lock or exit
|
||||
LOCK_DIR="lock"
|
||||
if ! mkdir "$LOCK_DIR" 2>/dev/null; then
|
||||
@ -58,6 +70,7 @@ if ! diff -q $RAW_CSV_FILE $TMP_CSV_FILE >/dev/null 2>&1; then
|
||||
current_year=$(date +'%Y')
|
||||
tail -n +2 $ALL_CSV_FILE | awk -v cy="$current_year" -F'/' '{ if ($1 >= cy) print }' >$CSV_FILE
|
||||
log "Changed"
|
||||
send_mail
|
||||
else
|
||||
log "No Change"
|
||||
rm $TMP_CSV_FILE
|
||||
|
Loading…
Reference in New Issue
Block a user