You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
43 lines
1.4 KiB
3 years ago
|
#!/bin/bash
|
||
|
|
||
|
# Shutdown Script
|
||
|
# ====================================================================
|
||
|
# I wrote this script with the intention of using it as part of a
|
||
|
# cron-job. Before you set up the cron-job, you must make sure you
|
||
|
# have either ran the "make-log-files.sh" script or created the
|
||
|
# appropriate log file and folder at the location specified at
|
||
|
# "logFile" below.
|
||
|
# As an aside, I usually set-up as alias for "shutdown" called,
|
||
|
# "powerdown". When I enter "powerdown" into the terminal, this script
|
||
|
# should ran and then the "shutdown" command is ran at the end. The
|
||
|
# "sleep" part is to give "curl" a bit of a buffer to finish its task.
|
||
|
# I have found it sometimes fails otherwise.
|
||
|
|
||
|
logDate=$(date '+%Y-%m-%dT%TZ')
|
||
|
logFile="/home/rtrp/logs/shutdown-logs.txt"
|
||
|
mainURL="http://ritherdon.abbether.net/api/status/update" # Make sure this is valid.
|
||
|
|
||
|
getApiUrl () {
|
||
|
case $HOSTNAME in
|
||
|
(factory1) apiURL="${mainURL}/1";;
|
||
|
(factory2) apiURL="${mainURL}/2";;
|
||
|
(factory3) apiURL="${mainURL}/3";;
|
||
|
(gallery1) apiURL="${mainURL}/4";;
|
||
|
(gallery2) apiURL="${mainURL}/5";;
|
||
|
(gallery3) apiURL="${mainURL}/6";;
|
||
|
esac
|
||
|
}
|
||
|
|
||
|
logStatusChange () {
|
||
|
cat << EOF >> $logFile
|
||
|
$logDate
|
||
|
EOF
|
||
|
}
|
||
|
|
||
|
logStatusChange
|
||
|
getApiUrl
|
||
|
|
||
|
curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/html' -d '{"status": "off", "time": "'${logDate}'", "token": "QWERTYuiopasdfghjklzxcvbnm_1234567890"}' "${apiURL}"
|
||
|
|
||
|
/sbin/shutdown -h now
|