Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #a test script to test how the api call to get badgeback emails for the given email list handles multiple parameters
- function help {
- echo "USAGE: ./test1.sh or ./test1.sh help for showing help message. example: ./test1.sh > results.json to redirect output to another file"
- exit 0
- }
- if [ $# -eq 1 ]
- then
- if [ $1 == "help" ]
- then
- help
- fi
- fi
- #parameters for the api call, a list of emails
- file="emails.txt"
- #how many parameters
- mail_count=$(cat $file | wc -l)
- #convert to integer by adding 0:p
- mail_count=$(($mail_count+0))
- #echo $mail_count
- #form the json array for the emails
- json_arr="["
- i=1
- quote="\""
- #kinda like "join" call in another languages, forms a comma separated list in the form of ["mail1","mail2","mail3",...."mailn"]
- while read line
- do
- #if [ $i -eq $mail_count ]
- #then
- # break
- #fi
- json_arr+=$quote
- json_arr+=$line
- json_arr+=$quote
- if [ $i -ne $mail_count ]
- then
- json_arr+=","
- fi
- i=$((i + 1))
- done <$file
- json_arr+="]"
- json_data="{\"mails\":$json_arr}"
- #echo $json_data
- curl -X POST -H 'Content-Type: application/json' -d $json_data http://localhost/osaamispilvi/drupal/badgeback_email_list --user obf_api:QF2f8urbaM8oiytDyjm6ZREObRJduOGj2dOfoFCI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement