Advertisement
Guest User

asdfasdf

a guest
Jul 31st, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.30 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #a test script to test how the api call to get badgeback emails for the given email list handles multiple parameters
  4.  
  5. function help {
  6.     echo "USAGE: ./test1.sh or ./test1.sh help for showing help message. example: ./test1.sh > results.json to redirect output to another file"
  7.     exit 0 
  8. }
  9.  
  10. if [ $# -eq 1 ]
  11. then
  12.     if [ $1 == "help" ]
  13.     then
  14.         help
  15.     fi
  16. fi
  17.  
  18. #parameters for the api call, a list of emails
  19. file="emails.txt"
  20. #how many parameters
  21. mail_count=$(cat $file | wc -l)
  22. #convert to integer by adding 0:p
  23. mail_count=$(($mail_count+0))
  24. #echo $mail_count
  25.  
  26. #form the json array for the emails
  27. json_arr="["
  28. i=1
  29. quote="\""
  30.  
  31. #kinda like "join" call in another languages, forms a comma separated list in the form of ["mail1","mail2","mail3",...."mailn"]
  32. while read line
  33. do
  34.     #if [ $i -eq $mail_count ]
  35.     #then
  36.     #    break
  37.     #fi
  38.     json_arr+=$quote
  39.     json_arr+=$line
  40.     json_arr+=$quote
  41.    
  42.     if [ $i -ne $mail_count ]
  43.     then
  44.         json_arr+=","
  45.     fi
  46.  
  47.     i=$((i + 1))
  48. done <$file
  49.  
  50. json_arr+="]"
  51.  
  52. json_data="{\"mails\":$json_arr}"
  53. #echo $json_data
  54. 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