Last active
December 19, 2022 16:27
-
-
Save ramit-mitra/32f3844608c2af97fc8a41bcc1f48ee5 to your computer and use it in GitHub Desktop.
Personal CRON tasks (for Ubuntu)
This file contains hidden or 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 | |
# Personal cron tasks script file | |
# General housekeeping stuff | |
# Example usage: | |
# curl -s https://gist.githubusercontent.com/ramit-mitra/32f3844608c2af97fc8a41bcc1f48ee5/raw/cron_tasks.sh | bash | |
hour=$(date +"%H") | |
minute=$(date +"%M") | |
if true; then | |
# do nothing | |
echo "--- running cron script \n" | |
fi | |
# runs every hour | |
if (( $hour % 1 == 0 )) && [ "$minute" = "00" ]; then | |
# update packages | |
apt update -y | |
apt upgrade -y | |
apt autoremove -y | |
# restart services (just to be safe) | |
systemctl restart ufw nextdns | |
fi | |
# runs every 6 hour | |
if (( $hour % 4 == 0 )) && [ "$minute" = "05" ]; then | |
# restart nginx | |
systemctl restart nginx | |
# renew ssl certs | |
certbot renew --post-hook "systemctl reload nginx" | |
# clear the swap memory | |
swapoff -a | |
swapon -a | |
fi | |
# runs every 12 hour | |
if (( $hour % 12 == 0 )) && [ "$minute" = "10" ]; then | |
echo "do nothing" | |
# import blocklisted IPs | |
# curl -s https://gist.githubusercontent.com/ramit-mitra/f5e9c4f9adc4a155ebcce2608bc50f39/raw/block_banned_ips.sh | bash | |
fi | |
# log message | |
echo "----- Cron tasks executed at $(date) \n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment