Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Downloading gzip'd tar file from web server to update NFS automounts
#!/bin/bash
# This script checks the timestamp of the fileURL and compares it against a locally
# cached timestamp. If the archive's timestamp is newer, then it gets downloaded,
# extracted into /etc/, and the automount cache gets flushed.
fileURL="http://server.name.here/path/to/automounts.tgz"
sleep 20
# Custom curl options
myCurl () { /usr/bin/curl --silent --show-error "$@"; }
# Get modification date of fileURL
modDate=$(myCurl --head $fileURL | awk -F': ' '/Last-Modified/{print $2}')
# update_automounts function, called only if needed
update_automounts () {
echo $modDate > /tmp/automounts_timestamp
myCurl --output /tmp/automounts.tgz $fileURL
# backup the original auto_master
if [ ! -f /etc/auto_master~orig ]; then
cp /etc/auto_master /etc/auto_master~orig
fi
# untar into place
tar zxf /tmp/automounts.tgz -C /etc
# purge automount cache
automount -vc && exit 0
}
# Compare timestamps and update automounts if needed.
if [ -f /tmp/automounts_timestamp ]; then
cachedDate=$(cat /tmp/automounts_timestamp)
if [ "$cachedDate" == "$modDate" ]; then
exit 0
else
update_automounts
fi
else
update_automounts
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment