1
我正在嘗試爲Nagios製作一個腳本來使用Sendgrid API發送郵件。在發送到sendgrid時,在Bash腳本中的變量中不能有空格API
當我沒有任何空間在我的身體/主題,它工作得很好。但是當我有它時,我得到這個錯誤:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 144 100 63 100 81 140 181 --:--:-- --:--:-- --:--:-- 181
curl: (3) [globbing] unmatched close brace/bracket in column 6
{"errors":[{"message":"Bad Request","field":null,"help":null}]}
這是我的腳本。
#!/bin/bash
sendgridapikey="................................................."
mailto="[email protected]"
mailfrom="[email protected]"
subject="subject here"
body="DefaultNagiosMailBody\n\nTest"
while getopts a:t:f:s:b: option
do
case "${option}"
in
a) sendgridapikey=${OPTARG};;
t) mailto=${OPTARG};;
f) mailfrom=${OPTARG};;
s) subject=${OPTARG};;
b) body=${OPTARG};;
esac
done
curl -X POST "https://api.sendgrid.com/v3/mail/send" -H "Authorization: Bearer $sendgridapikey" -H "Content-Type: application/json" -d \
'{"personalizations":[{"to":[{"email":"'$mailto'"}],"subject":"'$subject'"}],"from":{"email":"'$mailfrom'","name": "Nagios"},"content":[{"type":"text/plain","value":"'$body'"}]}'
謝謝你的解釋和解決方案Janos。 – Zucchini