使用shell脚本监控用户登陆服务器并发送提示信息给微信
1.需要在/etc/ssh/目录下面创建一个名为sshrc的文件,执行权限可给可不给,那么在有人通过ssh远程登录这台服务器的时候,这段脚本就会被执行
#!/bin/bash
###V1---### CropID='xxxxxxxxxx'
Secret='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
#Gtoken=$(/usr/bin/curl $GURL -H "DNT: 1" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: zh-CN,zh;q=0.8" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 BIDUBrowser/8.1 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "X-DevTools-Emulate-Network-Conditions-Client-Id: B546FC80-414C-403F-95F0-EB0F70E58EF7" -H "Connection: keep-alive" -H "Cache-Control: max-age=0" --compressed | awk -F \" '{print $4}')
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" '{print $10}')
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"
function body() {
local int appId=
#local userId=$
local userId="LinYouYi"
local partyId=
local msg='有用户上线请注意:\n主机名:'`hostname`'\n主机ip:'`curl ifconfig.me`'\n登录用户:'`whoami`'\n登录时间:'`date`
printf '{\n'
printf '\t"touser":"'"$userId"\"",\n"
printf '\t"toparty":"'"$partyId"\"",\n"
printf '\t"msgtype": "text",'"\n"
printf '\t"agentid":"'"$appId"\"",\n"
printf '\t"text":{\n'
printf '\t\t"content":"'"$msg"\"
printf '\n\t},\n'
printf '\t"safe":"0"\n'
printf '}\n'
}
#/usr/bin/curl --data-ascii "$(body $1)" $PURL
/usr/bin/curl --data-ascii "$(body)" $PURL
使用shell脚本监控用户登陆服务器并发送提示信息给微信的更多相关文章
- shell脚本ssh自动登陆服务器
#!/bin/shsshpass -p "your password" ssh user@ip 注意: 需要先安装sshpass: 源码下载地址:http://sourceforg ...
- shell脚本监控Linux系统性能指标
2016-11-04 22:41 原作者不详 分类: Linux(7) 在服务器运维过程中,经常需要对服务器的各种资源进行监控, 例如:CPU的负载监控,磁盘的使用率监控,进程数目监控等等,以在系统出 ...
- Linux简单Shell脚本监控MySQL、Apache Web和磁盘空间
Linux简单Shell脚本监控MySQL.Apache Web和磁盘空间 1. 目的或任务 当MySQL数据库.Apache Web服务器停止运行时,重新启动运行,并发送邮件通知: 当服务器磁盘的空 ...
- 用shell脚本监控进程是否存在 不存在则启动的实例
用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货: #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ]th ...
- linux shell脚本监控进程是否存在
用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货: #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ...
- 【转】shell脚本实现多台服务器自动巡检--可参考学习
shell脚本实现多台服务器自动巡检 摘要: 运维服务一个项目二十多台(或者多台)服务器,每天要做服务器的性能巡检工作是查看服务器的CPU.内存.磁盘空间是否在正常值范围内.像 ...
- shell脚本批量ssh登陆主机并执行命令
shell脚本批量ssh登陆主机并执行命令 今天在客户现场遇到了这个问题,客户没有管理工具,无法批量登陆主机下发命令,几个个C段啊,让我一个一个登陆,.................. 所以写了个s ...
- shell脚本监控网站状态
shell脚本监控网站状态 #!/bin/sh date=`date +"%Y%m%d-%H%M"` title="status" contentFail=&q ...
- shell脚本实现多台服务器自动巡检
shell脚本实现多台服务器自动巡检 摘要: 运维服务一个项目二十多台(或者多台)服务器,每天要做服务器的性能巡检工作是查看服务器的CPU.内存.磁盘空间是否在正常值范围内.像这样每天 ...
随机推荐
- 【转帖】oracle数据类型和对应的java类型
原文地址:http://otndnld.oracle.co.jp/document/products/oracle10g/102/doc_cd/java.102/B19275-03/datacc.ht ...
- [Node.js] 04 - Event and Callback
回调函数 回调函数在完成任务后就会被调用,Node 使用了大量的回调函数,Node 所有 API 都支持回调函数. 异步读取文件的回调函数: var fs = require("fs&quo ...
- post请求参数问题
from:https://www.cnblogs.com/btgyoyo/p/6141480.html jQuery的ajax方法和post方法分别发送请求,在后台Servlet进行处理时结果是不一样 ...
- cmake构建时指定编译器架构(x86 or x64)
vs2015 x64编译器为例,cmake命令如下: cmake -G "Visual Studio 14 Win64" path\to\source\dir 去掉Win64,就是 ...
- Gym 101149L Right Build
L. Right Build time limit per test 2.0 s memory limit per test 256 MB input standard input output st ...
- python 中的 print 函数与 list函数
print() 函数: 传入单个参数时默认回车换行,关键词 end 可以用来避免输出后的回车(换行), 或者以一个不同的字符串结束输出. >>> a, b = 0, 1 >& ...
- 设计模式学习--Prototype
What Prototype:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. Why Prototype适用于在一个类的实例有几种不同的状态组合的一种时,建立相应的数目的原型并克隆她 ...
- Linux关闭IPV6
Linux关闭IPV6的方法 修改配置文件/etc/sysctl.conf添加以下1行 net.ipv6.conf.all.disable_ipv6 = 1 设置生效 sysctl -p 查看没有IP ...
- easyui datagrid 弹出页面会出现两个上下滚动条处理办法!
同事推荐将datagrid上加一个toolbar 将上面的工具元素加上就可以了 toolbar: '#divListToolbar',
- 架构师如何借鉴他人经验快速成长? | 2018GIAC上海站日程上线!
随着网络技术的迅猛发展,越来越多的企业需要紧跟技术发展潮流以应对层出不穷的业务场景变化.如今多“语言”开发百花齐放,选择何种语言才能在合适的场景中发挥最大价值?互联网业务架构经过了长年的发展,已然朝着 ...