Created
July 26, 2016 22:32
-
-
Save sysarcher/6c211913eeadf31a200a3bddd016d086 to your computer and use it in GitHub Desktop.
Skip `apt-get update` if you've recently updated cache
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
function getLastAptGetUpdate() | |
{ | |
local -r aptDate="$(stat -c %Y '/var/cache/apt')" | |
local -r nowDate="$(date +'%s')" | |
echo $((nowDate - aptDate)) | |
} | |
# Default To 24 hours | |
updateInterval="$((24 * 60 * 60))" | |
lastAptGetUpdate="$(getLastAptGetUpdate)" | |
if [[ "${lastAptGetUpdate}" -gt "${updateInterval}" ]] | |
then | |
sudo apt-get update | |
else | |
#lastUpdate="$(date -u -d @"${lastAptGetUpdate}" +'%-Hh %-Mm %-Ss')" | |
echo "Skip apt-get update because it was run within ${updateInterval}sec" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment