本文最后更新于 1371 天前,其中的信息可能已经有所发展或是发生改变。
Webhook
首先申请企业微信,在群组中申请webhook api
创建脚本-任选一种
1.在/etc/ssh/下创建sshrc文件
vi /etc/ssh/sshrc
2.在/etc/profile.d/创建[name].sh
vi /etc/profile.d/login.sh
主程序
#!/bin/bash
remote=`who am i | awk '{ print $5 }' | sed 's/(//g' | sed 's/)//g'`
dizhi=`curl -q -s http://freeapi.ipip.net/$remote | awk -F '"' '{print $2"-"$4"-"$6}'`
mess=`echo -e "腾讯云香港有人登录了\nIP地址为:$remote\n登录的位置:$dizhi"`
#echo "$mess"
curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=**填自己的API**' -H 'Content-Type: application/json' -d '
{
"msgtype": "text",
"text": {
"content": "'"${mess}"'"
}
}' > /dev/null 2>&1
设置权限
chmod +x /etc/ssh/sshrc
重新连接
即可看到webhook发送的通知