使用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.内存.磁盘空间是否在正常值范围内.像这样每天 ...
随机推荐
- 正确释放WORD对象(COM组件) COMException: 被调用的对象已与其客户端断开连接
本来form method=post本页面 修改为其他页面 action=save.aspx后没问题 其他问题可参考以下: 引自:http://topic.csdn.net/u/20090108/17 ...
- 揭秘IT人才特点:中美印日四国程序员比较
不知道大家是否已经看过这篇文章,感觉比较客观. 来自:http://www.programmer.com.cn/282/ 最近以裁判的身份参加了公司举办的编程大赛,发现高手云集,对公 ...
- c# 中config.exe 引发的一些问题
public static void CreateConfig(){ //c#可以添加内置的app.config,我们通过ConfigrationManager类可以 //可以很轻松的操作相关节点,操 ...
- IOS多线程处理
http://www.jianshu.com/p/0b0d9b1f1f19 首页专题下载手机应用 显示模式登录 注册登录 添加关注 作者 伯恩的遗产2015.07.29 00:37* 写了35 ...
- 6.24 html书城Demo
<!DOCTYPE html> <!-- 睡觉,2018-6-24 22:04:36 还有foot没弄好明天弄--> <html> <head> < ...
- A - Fire Net
Suppose that we have a square city with straight streets. A map of a city is a square board with n r ...
- Goroutines
Go 语言中的并发可以用两种方式实现: 第一种方式,支持顺序通信进程(communicating sequential processes),简称 CSP.CSP是一种现代的并发编程模型,在这种编程模 ...
- ElasticSearch入门 第六篇:复合数据类型——数组,对象和嵌套
这是ElasticSearch 2.4 版本系列的第六篇: ElasticSearch入门 第一篇:Windows下安装ElasticSearch ElasticSearch入门 第二篇:集群配置 E ...
- DB2 rollforward 命令使用详解
DB2 rollforward 命令使用详解 原文:https://www.ibm.com/developerworks/cn/data/library/techarticles/dm-1003wuc ...
- 洛谷P1074 靶形数独【dfs】【剪枝】
题目:https://www.luogu.org/problemnew/show/P1074 题意: 数独的分数如下.一个数独的总分数就是权值乘所填数字之和. 现在给一个未完成的数独,问分数最高的数独 ...