Skip to content

Instantly share code, notes, and snippets.

@ramit-mitra
Last active December 19, 2022 16:27
Show Gist options
  • Save ramit-mitra/32f3844608c2af97fc8a41bcc1f48ee5 to your computer and use it in GitHub Desktop.
Save ramit-mitra/32f3844608c2af97fc8a41bcc1f48ee5 to your computer and use it in GitHub Desktop.
Personal CRON tasks (for Ubuntu)
#!/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