script to continuously upload random data to the safe network testnet and to verify data afterwards
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 | |
| # isu -- infinite safe upload | |
| msg() { | |
| printf '%s\n' "${0##*/}>> ${1}" | tee -a "test.log" | |
| } | |
| verify_put() { | |
| safeURL=$(echo "${3}" | grep -o ' | safe://[^ ]*' | grep -o 'safe://[^ ]*') | |
| safe cat "${safeURL}" >"${1}" | |
| [ "$(md5sum "${1}")" = "${2}" ] && msg "file: ${1} has good checksum" || msg "file: ${1} has BAD checksum" | |
| rm "${1}" | |
| } | |
| while true | |
| do | |
| filesize=$(shuf -i 10000-9000000 -n 1) | |
| filename=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16) | |
| head -c "${filesize}" </dev/urandom >"${filename}" | |
| checksum=$(md5sum "${filename}") | |
| counter=$((counter + 1)) | |
| TBU=$(($TBU + $filesize)) | |
| msg "uploading filename:${filename} -- size in bytes:${filesize}; please wait ..." | |
| safeOutput="$(safe files put "${filename}")" | |
| while [[ "${safeOutput}" =~ "Error" ]] | |
| do | |
| errcounter=$((errcounter + 1)) | |
| msg "Error during upload, retrying; please wait ..." | |
| safeOutput="$(safe files put "${filename}")" | |
| done | |
| msg "${safeOutput}" | |
| msg "Error Ratio:${errcounter}/${counter} (errors per total uploads) -- total bytes uploaded:${TBU}" | |
| rm "${filename}" | |
| verify_put "$filename" "$checksum" "${safeOutput}" & | |
| sleep "$(shuf -i 1-10 -n 1)s" | |
| done | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment