-
-
Save radiowave911/4ef2646542b885edea22cd05258cea21 to your computer and use it in GitHub Desktop.
Working script (sanitized)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is run weekly by CRON on Thursdays to download <redacted> | |
# Function to sync the <redacted> directory with the ownCloud server | |
function ownCloudSync { | |
owncloudcmd -s --non-interactive --trust --user <username> --password <password> /var/opt/<redacted>/ https://<OwnCloud Server>/remote.php/dav/files/<redacted>/<redacted>/ | |
EXIT=$? | |
logger -p user.err "LRJ OwnCloud Exit Code ${EXIT}" | |
} | |
# Get the current date and format it as yyyy-mm-dd | |
DATE=$(date +%Y-%m-%d) | |
# Construct the URL for the file | |
URL="http://<download_host>/li/LRJ_${DATE}.mp3" | |
ALTURL="http://<download_host>/li/lrj_${DATE}.mp3" | |
# Download the file and save it to /var/opt/<redacted>/ | |
wget -q -t 5 --no-cache -P /var/opt/<redacted>/ ${URL} | |
EXIT=$? | |
# Check if the download was successful | |
if [ ${EXIT} -ne "0" ]; then | |
if [ ${EXIT} -ne "8" ]; then | |
logger -p user.err "LRJ wget download failed: ${URL} Exitcode: ${EXIT}" | |
exit 1 | |
else | |
# Download the file using the alternate URL and save it to /var/opt/<redacted>/ | |
wget -q -t 5 --no-cache -P /var/opt/<redacted>/ ${ALTURL} | |
EXIT=$? | |
# Check if the download was successful | |
if [ ${EXIT} -ne "0" ]; then | |
logger -p user.err "LRJ wget download failed: ${ALTURL} Exitcode: ${EXIT}" | |
exit 1 | |
fi | |
fi | |
fi | |
# Wait for the ownCloud sync to complete | |
ownCloudSync | |
EXIT=$? | |
# Check if the last ownCloud sync was successful | |
if [ ${EXIT} -ne "0" ]; then | |
logger -p user.err "LRJ ownCloud sync failed: ${URL} Exitcode: ${EXIT}" | |
exit 2 | |
fi | |
# Delete the previous week's file | |
rm -f /var/opt/<redacted>/<redacted> | |
logger -p user.info "Download completed successfully: ${URL}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment