Created
August 30, 2019 04:14
-
-
Save wsams/27aca96daa666f4d59320ace594cf733 to your computer and use it in GitHub Desktop.
Simple way to trap and clean up temporary files in BASH - This script is useful as a cron job to keep an Ubuntu machine upgraded automatically
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 | |
# Simple way to trap and clean up temporary files in BASH - This script is useful as a cron job to keep an Ubuntu machine upgraded automatically | |
# The following cron job would keep the system up-to-date 4 times a day: 0 */4 * * * /root/bin/system-upgrade.sh | |
pidfile="/root/bin/system-upgrade.pid" | |
janitor() { | |
rm -f $pidfile | |
} | |
#0 success | |
#1 incorrect invocation or permissions | |
#2 system error (out of memory, cannot fork, no more loop devices) | |
#4 internal mount bug or missing nfs support in mount | |
#8 user interrupt | |
trap janitor 0 1 2 4 8 | |
if [[ -e $pidfile ]]; then | |
exit 1 | |
else | |
touch $pidfile | |
fi | |
apt update && apt -y upgrade |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment