Skip to content

Instantly share code, notes, and snippets.

@michimau
Last active July 22, 2022 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michimau/f49078322452fdb9acc44dcacd632c7d to your computer and use it in GitHub Desktop.
Save michimau/f49078322452fdb9acc44dcacd632c7d to your computer and use it in GitHub Desktop.
downloads files from the cms to the filesystem of sdi
#!/bin/bash
scriptdir=/opt/cms2sdi
basedir=/var/local/gis_sdi/continental/tabular
excelfile=https://shareit.eea.europa.eu/s/BMDXbQHMt7wwxfW/download
wget -l --content-disposition -nc $excelfile
xlsx2csv -s 3 -d='tab' -q='all' download | awk 'BEGIN { FS = "[\t]+" } ; { print $5,$24 }' > $scriptdir/cms2sdi.txt
mkdir -p $basedir
cd $basedir
rm -rf $scriptdir/dodownload.sh
touch $scriptdir/dodownload.sh
echo "cd $basedir" >> $scriptdir/dodownload.sh
while read id links ; do
id=$(sed -e 's/^"//' -e 's/"$//' <<< "$id")
echo "mkdir $basedir/$id" >> $scriptdir/dodownload.sh
echo "cd ./$id" >> $scriptdir/dodownload.sh
echo
echo ./$id
echo
echo $links
#echo $links | awk -F'###' '{ for ( i=1; i<=NF; i i++ ) { if($i ~ /cmshare/) { print "wget -nc --content-disposition " $i } else { print "wget -nc --content-disposition " $i"/at_download/file" }} }' | bash
echo $links | awk -F'###' '{ for ( i=1; i<=NF; i i++ ) { if($i ~ /cmshare/) { print "wget -nc --content-disposition " $i"\n" } else { print "wget -nc --content-disposition " $i"/at_download/file\n" }} }' >> $scriptdir/dodownload.sh
#| bash
echo "cd $basedir" >> $scriptdir/dodownload.sh
done < $scriptdir/cms2sdi.txt
echo "chown -R www-data:www-data $basedir" >> $scriptdir/dodownload.sh
sed 's/\"//g' $scriptdir/dodownload.sh > $scriptdir/dodownload2.sh
mv $scriptdir/dodownload2.sh $scriptdir/dodownload.sh
chmod a+x $scriptdir/dodownload.sh
#/bin/bash $scriptdir/dodownload.sh || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment