Skip to content

Instantly share code, notes, and snippets.

@victor-oliveira1
Last active October 20, 2021 03:37
Show Gist options
  • Save victor-oliveira1/07c86ea602c29d7713092e7c37705a9c to your computer and use it in GitHub Desktop.
Save victor-oliveira1/07c86ea602c29d7713092e7c37705a9c to your computer and use it in GitHub Desktop.
Sync crontab using pastebin service
#!/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