1.apache web 服务器

1
2
3
4
5
6
7
8
9
10
!/bin/bash
# 表示请求链接3秒钟,不要返回的测试数据
nc -3 localhost 80 &>/dev/null
if [ $? -eq 0 ];then
        str="apache web status Running!"
else
        str="apache web status Shuting!"
fi
# 发送的主题,邮件地址
echo str|mail -'apache web server' admin@lampym.com

2.监控mysql

1
2
3
4
5
6
7
8
9
10
!/bin/bash
# 表示请求链接3秒钟,不要返回的测试数据
nc -3 localhost 3306 &>/dev/null
if [ $? -eq 0 ];then
        str="mysql server status Running!"
else
        str="mysql server status Shuting!"
fi
# 发送的主题,邮件地址
echo str|mail -'mysql server status' admin@lampym.com

3.监控服务器disk

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
:<<!
NR表示行数,$5表示第5列,具体的自己根据实际调整
!
ds=`df |awk '{if(NR==4){print int($5)}}'`
# 这里45根据实际需要更改
if [ $ds -lt 45 ];then
    str="disk space is less then!!!"
else
    str="disk space is greate than 45%!!!"
fi
echo $str|mailx -'linux server disk space' admin@lampym.com

4.监控服务器monery 

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
:<<!
具体的自己根据实际调整
!
mery=`df |awk '{if(NR==2){print int($3*100/$2)}}'`
if [ $mery -lt 50 ];then
    str="mery space is less then 50%!!!"
else
    str="mery space is greate than 50%!!!"
fi
echo $str|mailx -'linux server mery space' admin@lampym.com

整合一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# 功能:监控资源
# 名称:cont.sh
# 作者:枫客浪人
# 版本:0.1
# 联系方式:xxxx
# apache 应用服务
apache_web(){
    nc -3 localhost 80 &>/dev/null
  if [ $? -eq 0 ];then
        str="apache web status Running!"
  else
        str="apache web status Shuting!"
  fi
    # 发送的主题,邮件地址
  echo str|mail -'apache web server' admin@lampym.com
}
# mysql 服务
mysql_db(){
    nc -3 localhost 3306 &>/dev/null
    if [ $? -eq 0 ];then
        str="mysql server status Running!"
    else
        str="mysql server status Shuting!"
    fi
        # 发送的主题,邮件地址
    echo str|mail -'mysql server status' admin@lampym.com
}
# 磁盘使用情况
disk_mnt(){
    ds=`df |awk '{if(NR==4){print int($5)}}'`
    # 这里45根据实际需要更改
    if [ $ds -lt 45 ];then
        str="disk space is less then!!!"
    else
    str="disk space is greate than 45%!!!"
    fi
    echo $str|mailx -'linux server disk space' admin@lampym.com
}
# 内存使用情况
meny_mnt(){
    mery=`df |awk '{if(NR==2){print int($3*100/$2)}}'`
    if [ $mery -lt 50 ];then
    str="mery space is less then 50%!!!"
    else
    str="mery space is greate than 50%!!!"
    fi
    echo $str|mailx -'linux server mery space' admin@lampym.com
}
min(){
apache_web()
mysql_db()
disk_mnt()
meny_mnt()
}
crontab -e

每天13:10分执行代码发送一份邮件

Linux记录-shell实现脚本监控服务器及web应用的更多相关文章

  1. shell实现脚本监控服务器及web应用

    实际工作中我们需要知道部署在服务器上的应用有没有问题,但是人为的操作太麻烦有咩有简单的方式呢shell来监控我们服务器运行状态以及服务器上部署的应用,如果出现异常就会自动发送一个邮件给我们,开始搞起. ...

  2. Linux下shell通用脚本启动jar(微服务)

    Linux下shell通用脚本启动jar(微服务) vim app_jar.sh #!/bin/bash #source /etc/profile # Auth:Liucx # Please chan ...

  3. linux 下shell 编写脚本

    linux 下shell 编写脚本: 1.程序结构练习:编写一个脚本,给定一个正整数,计算出这个数所有位的数字之和. 例如:程序给定输入123,那么应该返回1+2+3=6. 2.程序结构练习:编写一个 ...

  4. Linux记录-shell自动化批量部署sql脚本并记录日志信息(转载)

    #!/bin/bash #script_version=v110 db_host=127.0.0.1 db_port=3306 db_username=db_test_inst db_passwd=` ...

  5. Linux记录-shell 100例(转载)

    1.编写hello world脚本 #!/bin/bash # 编写hello world脚本 echo "Hello World!" 2.通过位置变量创建 Linux 系统账户及 ...

  6. Linux CAN Shell 测试脚本程序

    2012-01-13 22:57:14 为我的开发板2440做二次开发,添加了can驱动,做了驱动测试程序,没理由不添加一个测试脚本程序啊!修改了测试程序,使应用程序更加灵活,添加了一下传递参数.接着 ...

  7. Linux记录-shell获取hdfs表查询mysql

    #!/bin/sh hdfs dfs -ls /user/hive/warehouse | awk '{print $8}' | awk -F "/" '{print $5}' & ...

  8. Linux记录-shell获取hdfs used使用

    #!/bin/bash export JAVA_HOME=/app/jdk/jdk1.8.0_92 export HADOOP_HOME=/app/hadoop export HADOOP_CONF_ ...

  9. Linux记录-shell一行代码杀死进程(收藏)

    ps -ef |grep hello |awk '{print $2}'|xargs kill -9

随机推荐

  1. Android Dialog 简单封装

    转载:https://www.cnblogs.com/zjjne/archive/2013/10/03/3350382.html public class MyAlertDialog { //regi ...

  2. 【XSY2708】hack 网络流

    题目描述 给你一个图,每条边有一个权值.要求你选一些边,满足对于每条从\(1\)到\(n\)的路径上(可以不是简单路径)有且仅有一条被选中的边.问你选择的边的边权和最小值. \(n\leq 100\) ...

  3. 【XSY2472】string KMP 期望DP

    题目大意 给定一个由且仅由字符'H','T'构成的字符串\(S\). ​ 给定一个最初为空的字符串\(T\) ,每次随机地在\(T\)的末尾添加'H'或者'T'. 问当\(S\)为\(T\)的后缀时, ...

  4. Ionic3的http请求如何实现token验证,并且超时返回登录页

    要求 后台提供的接口,不能让人随便输入个链接就能访问,而是要加入一个token,token是动态的,每次访问的时候判断,有权限并且未过期的时候才可以访问接口. 后台的设计是 在登录的时候,首先要pos ...

  5. python学习日记(join,range)

    join方法 join方法用于将序列里的字符串以指定的字符串连接成一个新的字符串 s = 'fasfw123' s1 = '-'.join(s) print(s1) str = '&ooooo ...

  6. Educational Codeforces Round 54 [Rated for Div. 2] (CF1076)

    第一次在宿舍打CF 把同宿舍的妹子吵得不行... 特此抱歉QAQ A 题意:给定一个字符串, 最多删掉一个字符,使得剩余字符串字典序最小 n<=2e5 当然"最多"是假的 删 ...

  7. 自学Python之路-Python核心编程

    自学Python之路-Python核心编程 自学Python之路[第六回]:Python模块       6.1 自学Python6.1-模块简介    6.2 自学Python6.2-类.模块.包  ...

  8. css颜色表示法

    css颜色值主要有三种表示方法: 1.颜色名表示,比如:red 红色,gold 金色 2.rgb表示,比如:rgb(255,0,0)表示红色 3.16进制数值表示,比如:#ff0000 表示红色,这种 ...

  9. 解决 pip attributeerror 'nonetype' object has no attribute 'bytes'

    for Windows : python -m pip install -U pip for Linux : pip install -U pip

  10. MineSite

    country:http://s01.flagcounter.com/more/SoJN/