Linux 用户登录微信机器人告警

40 篇文章 2 订阅
tee sshx.sh <<-'EOF'
#!/bin/bash
whoip=`who am i |awk -F '[()]' '{print $2}'`
city=`curl -s https://ip.cn/index.php?ip=$whoip | grep 'id="tab0_address"' | cut -b 44-74 | sed s/[[:space:]]//g`
hostnam=`hostname`
ip=`ifconfig eth0|awk -F '[ :]+' 'NR==2 {print $3}'`
who=`whoami`
timers=`date '+%Y-%m-%d-%H:%M:%S'`

#msg='请检查服务器登录用户:\n主机名: '`hostname`'\n主机IP: '`ifconfig eth0|awk -F '[ :]+' 'NR==2 {print $3}'`'\n登录用户: '`whoami`'\n登录IP: '`who am i |awk -F '[()]' '{print $2}'`'\n登录时间: '`date '+%Y-%m-%d-%H:%M:%S'`''
token="4f5e208c-1108-4a94-a8d2-12fab9ba2"
 
   curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='$token'' \
   -H 'Content-Type: application/json' \
   -d '
   {
        "msgtype": "markdown",
         "markdown": {      
            "content": "#### 主机名:'$hostnam'
            >### 主机IP:'$ip'
            >### 登录用户:'$who'
            >### 登录IP: '$whoip'
            >### 登录时间:'$timers'
            >### 来自:'$city'"
         }
        }' >/dev/null 2>/dev/null
exit 0
EOF
  • vim /etc/profile
/bin/bash  /root/wxchat.sh

在这里插入图片描述

  • 网络测试获取公网IP
curl ident.me
curl icanhazip.com
curl whatismyip.akamai.com
curl tnx.nl/ip
curl myip.dnsomatic.com
  • 日志分析
cat access.log | awk '{print $1}' | sort | uniq -c | sort -nr | awk '{print $2}' > log.txt
#!/bin/bash

for ip in `cat log.txt`; do
iplist=`curl -s   --user-agent foobar https://ip.cn/index.php?ip=$ip | grep 'id="tab0_address"' | cut -b 44-77 | sed s/[[:space:]]//g`
echo "$ip >>$iplist"
#curl -s  --user-agent foobar https://ip.cn/index.php?ip=$ip|grep '所在地理位置'|awk -F '>' '{print $5,$9,$12}'|awk -F '[</]+' '{print $1,$2,$3}' |awk -F ' ' '{print $1,$3,$4,$NF}' 
sleep 0.2
done

在这里插入图片描述

以下飞书登录

#!/bin/bash
whoip=`who am i |awk -F '[()]' '{print $2}'`
city=`curl -s https://ip.cn/index.php?ip=$whoip | grep 'id="tab0_address"' | cut -b 44-74 | sed s/[[:space:]]//g`
hostnam=`hostname`
ip=`ifconfig eth0|awk -F '[ :]+' 'NR==2 {print $3}'`
who=`whoami`
timers=`date '+%Y-%m-%d-%H:%M:%S'`
token="5607fcc9-34f4-4bff-9c32-22b01a295679"
usl="https://open.feishu.cn/open-apis/bot/v2/hook/5607fcc9-34f4-4bff-9c32-22b01a295679"
curl -X POST -H "Content-Type: application/json" \
      -d '{"msg_type":"text","content":{"text":"主机IP: '$ip'\n登录用户: '$who'\n 登录IP: '$whoip'\n 登录时间:'$timers'\n 来自:'$city'"}}' $usl >/dev/null 2>/dev/null
exit 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值