腳本內(nèi)容
###使用釘釘機(jī)器人接口進(jìn)行post數(shù)據(jù)
###使用bash
####添加登陸腳本
###vim .bash_profile
###sh /opt/login.sh
###debian 在.profile 添加要執(zhí)行的腳本
#!/bin/bash
###接口地址由釘釘機(jī)器人獲刃帕浮(直接復(fù)制粘貼)
url=https://oapi.dingtalk.com/robot/s*****
##獲取登陸用戶(hù)名
u=$USER
###獲取登錄時(shí)間(無(wú)法使用空格)
b=$(date '+%Y-%m-%d,%H:%M:%S')
###獲取登錄主機(jī)命
h=`hostname`
##獲取最后登錄的ip
userip=`lastlog -u root | awk '{print $3}'|sed -n '2p'`
##echo輸出
a=$(echo "當(dāng)前主機(jī)為:$h,當(dāng)前登錄主機(jī)ip為:$hip,當(dāng)前登錄用戶(hù):$u,當(dāng)前時(shí)間登陸時(shí)間:$b,當(dāng)前登錄的用ip:$userip")
#echo $a
##對(duì)機(jī)器人post數(shù)據(jù)
c=`curl -s -H "Content-type: application/json" -X POST -d '{"msgtype":"text","text":{"content":"'$a'"},"at":{"atMobiles":["189xxxx8325","189xxxx8325"]}}' $url`
echo $c,$b >> /var/log/login.log >/dev/null
釘釘機(jī)器人使用
傳送門(mén)
更多post數(shù)據(jù)類(lèi)型請(qǐng)查看釘釘機(jī)器人幫助文檔
極速linux-專(zhuān)注開(kāi)源