Last active
October 20, 2021 03:37
-
-
Save victor-oliveira1/07c86ea602c29d7713092e7c37705a9c to your computer and use it in GitHub Desktop.
Sync crontab using pastebin service
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
#!/usr/bin/env bash | |
# Sync crontab using pastebin service | |
# Victor Oliveira <[email protected]> | |
CRONFILE="/tmp/crontab.old" | |
CRONFILENEW="/tmp/crontab.new" | |
PBURL="https://pastebin.com/raw/YOUR_PASTE" | |
# Download crontab from pastebin | |
curl -s "${PBURL}" > "${CRONFILENEW}" || { | |
echo "Failed to download crontab file" | |
exit 1 | |
} | |
# Convert ISO8859 to UTF8 | |
dos2unix -q "${CRONFILENEW}" | |
# Check for changes | |
crontab -l > "${CRONFILE}" | |
diff -q "${CRONFILE}" "${CRONFILENEW}" &> /dev/null && { | |
rm -rf "${CRONFILE}" "${CRONFILENEW}" | |
exit 0 | |
} | |
# Ensure crontab sync | |
grep "\*/5 \* \* \* \* ./scripts/crontab-sync.sh" "${CRONFILENEW}" &> /dev/null || { | |
echo >> "${CRONFILENEW}" | |
echo "# Crontab Sync" >> "${CRONFILENEW}" | |
echo "*/5 * * * * ./scripts/crontab-sync.sh" >> "${CRONFILENEW}" | |
} | |
# Install new crontab | |
cat "${CRONFILENEW}" | crontab | |
# Clean temp files | |
rm -rf "${CRONFILE}" "${CRONFILENEW}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment