Skip to content

Instantly share code, notes, and snippets.

@NoSkillGuy
Created October 18, 2018 18:12
Show Gist options
  • Save NoSkillGuy/71c55f589b71d5eac82b3d7d85fe1d8a to your computer and use it in GitHub Desktop.
Save NoSkillGuy/71c55f589b71d5eac82b3d7d85fe1d8a to your computer and use it in GitHub Desktop.
A simple script to upload to Azure blob storage
#!/bin/bash
source $HOME/.profile
azure_uploads="$(find /path_to_uploads -type f)"
for current_file in $azure_uploads
do
current_file_md5_hash="$(echo $(md5sum $current_file | nawk '{print $1}') | xxd -r -p | base64)"
az storage blob upload -f $current_file -c reports -n $current_file --account-name $AZURE_STORAGE_NAME --account-key $AZURE_STORAGE_KEY --content-md5 $current_file_md5_hash
uploaded_file_md5_hash="$(az storage blob show --container-name reports --name $current_file --account-name $AZURE_STORAGE_NAME --account-key $AZURE_STORAGE_KEY --query properties.contentSettings.contentMd5)"
if [ "\"$current_file_md5_hash\"" == $uploaded_file_md5_hash ];
then
echo "File uploaded Successfully\nNow removing $current_file"
rm $current_file
else
echo "*[ERROR]* uploaded file *$current_file_name* with md5 ($current_file_md5_hash) and local file *\"$(basename $each_file)\"* with md5 ($uploaded_file_md5_hash) - *md5 hash doesn't match*"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment