Created
September 10, 2017 10:48
-
-
Save zymr-keshav/d43c326d71ca18c3a07e2cc31d3835aa to your computer and use it in GitHub Desktop.
curl using bash script with post data which have current time and random number
This file contains hidden or 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 | |
# call as `sh app.sh -u <app uuid> -i <app ip> -t <url>` | |
# exmaple sh app.sh -u 595e341fd7391071d21ce1b5 -i 20.20.1.73 -t /monitor/application/acme/ | |
# if you do not want to use - argument than comment while loop and uncomment commented uuid and ip | |
while getopts u:i:t: option | |
do | |
case "${option}" | |
in | |
u) uuid=${OPTARG};; | |
i) ip=${OPTARG};; | |
t) target_url=${OPTARG};; | |
esac | |
done | |
header="Content-Type: application/json" | |
enc=$(gshuf -i 0-1000 -n 1) #generate random number (in unix use shuf , remove prefix g) | |
dec=$(gshuf -i 10-600 -n 1) | |
num=$(gshuf -i 1000-50000 -n 1) | |
now=$(gdate +%s%3N) #generate current time in miliseconds (in unix use date, remove prefix g ) | |
#uuid=$1 #first argument | |
#ip=$2 #second argument | |
url_trim=${target_url%/} #remove trailing slash, if any | |
url_=${url_trim#/} #remove leading slash, if any | |
POST_DATA=$(cat <<EOF | |
{ | |
"baffleShield_id": "$uuid", | |
"num_sql_operations": $num, | |
"ip_address": "$ip", | |
"num_records_1": $enc, | |
"num_records_2": $dec, | |
"epoch_time": $now | |
} | |
EOF | |
) | |
POST_URL="http://127.0.0.1:8553/$url_/$uuid" | |
echo "$POST_DATA" | |
echo "$POST_URL" | |
curl -k -X POST -H "$header" -d "$POST_DATA" "$POST_URL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment