Я хочу отправить электронное письмо, когда что-то случилось с моим мессенджером dingtalk, я использовал этот код
webhook="https://oapi.dingtalk.com/robot/send?access_token=xxxxxx";
data=array("msgtype"=>"text","text" => array("content" => $MESSAGE));
data_string=json_encode($data);
ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $webhook);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/json;charset=utf-8"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
, когда я запускаю файл, вывод был
syntax error near unexpected token `('.
data=array('msgtype=(text)' 'text=(array('content=($MESSAGE)'))')'
, возможно, нет unix язык. Я пытался изменить код на
webhook="https://oapi.dingtalk.com/robot/send?access_token=xxxxxx";
data=array('msgtype=(text)' 'text=(array('content=($MESSAGE)'))')
data_string=json_encode($data);
ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $webhook);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/json;charset=utf-8"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
, это мой полный сценарий
SITESFILE=sitesweb.txt #list the sites you want to monitor in this file
EMAILS="xxx@xxx.com" #list of email addresses to receive alerts (comma separated)
while read site; do
if [ ! -z "${site}" ]; then
CURL=$(curl -s --head $site)
if echo $CURL | grep "200 OK" > /dev/null
then
echo "The HTTP server on ${site} is up!"
else
MESSAGE="This is an alert that your site ${site} has failed to respond 200 OK."
for EMAIL in $(echo $EMAILS | tr "," " "); do
SUBJECT="$site (http) Failed"
echo "$MESSAGE" | mail -s "$SUBJECT" $EMAIL
echo $SUBJECT
echo "Alert sent to $EMAIL"
webhook="https://oapi.dingtalk.com/robot/send?access_token=xxxxx";
data=array("msgtype"=>"text","text" => array("content" => $MESSAGE));
data_string=json_encode($data);
ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $webhook);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/json;charset=utf-8"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
done
fi
fi
done < $SITESFILE