Created
May 4, 2012 09:15
-
-
Save denitram/2593514 to your computer and use it in GitHub Desktop.
Admin-scripts: get spa-types from public server
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
#!/bin/bash | |
SPA_DIR=/data/spa-types/ | |
SPA_FILE=spatypes.txt | |
HEADER="type,profile" | |
SPA_URL=http://spaserver2.ridom.de/dynamic/spatypes.txt | |
SPA_LOG=wget.log | |
DATUM="`date +%y%m%d%H%M`" | |
HTTP_PROXY=http_proxy=http://wwwproxy-dmz.rivm.nl:8080/ | |
export $HTTP_PROXY | |
####################################################### | |
# Get the spa-types file | |
###################################################### | |
cd ${SPA_DIR} | |
if [ -f $SPA_FILE ]; | |
then | |
cp $SPA_FILE $SPA_FILE-$DATUM | |
wget $SPA_URL -a $SPA_LOG -O $SPA_FILE-NEW | |
else | |
wget $SPA_URL -a $SPA_LOG -O $SPA_FILE-NEW | |
fi | |
###################################################### | |
# If not exists append header line | |
###################################################### | |
if ! $(/bin/grep ${HEADER} $SPA_FILE-NEW >/dev/null 2>&1) | |
then | |
sed -e '1i \type,profile' $SPA_FILE-NEW > $SPA_FILE-TMP | |
sed -i 's/^M//g' $SPA_FILE-TMP | |
mv $SPA_FILE-TMP $SPA_FILE-NEW | |
fi | |
###################################################### | |
# Check the downloaded file - when empty do nothing for now, | |
# just keep the latest valid version | |
###################################################### | |
if [ -s $SPA_FILE-NEW ]; | |
then | |
mv $SPA_FILE-NEW $SPA_FILE | |
fi | |
###################################################### | |
# Clean up files older then 48 hours | |
###################################################### | |
bu_files="`find ${SPA_DIR} -type f -mtime +1 -name spatypes\.txt-1\*`" | |
for f in ${bu_files}; do | |
#ls -l $f | |
rm ${f} | |
done | |
#eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment