1. 程式人生 > >shell腳本實現企業微信報警

shell腳本實現企業微信報警

w3c cgi msg -- follow ont art \n sage

function sendmsg() {

CorpID="ww3c6298264d839e2f"
Secret="YvyMQpMRIoXtdQRWo0RNkMBTZnHWKvBwC3ILkyuCsKQ"
agentid=1000002

GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CorpID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL|awk -F\" ‘{print $10}‘)

#echo $Gtoken
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"

Ip=$(ip a |grep ens33 |grep inet|awk -F "/" ‘{ print $1 }‘ |awk -F " " ‘{ print $2 }‘)

/usr/bin/curl --data-ascii ‘{
"touser": "@all",
"toparty": "2",
"msgtype": "text",
"agentid": "1000002",
"text": {"content": "‘"警告:[$msg]\n主機:[uname -n

]\n日期:[$(date +%F-%T)]\n地址:[$Ip]"‘"},
"safe":"0"

}‘ $PURL >/dev/null 2>&1
}

shell腳本實現企業微信報警