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. Redis——redis使用redis-dump,redis-load导出导入数据——【三】

    来源 https://www.cnblogs.com/dadonggg/p/8662455.html https://blog.csdn.net/chenxinchongcn/article/deta ...

  2. 洛谷P1414又是毕业季二题解

    题目 思想: 首先这个题必定是一个数学题,肯定不是一个一个枚举得到解,这样肯定会T,所以我们就应该想一些别的方法,. 分析: 比如,答案,一定是递减的,因为该答案所满足的条件肯定是越来越苛刻的,所以我 ...

  3. mysql查询同一个字段下,不同内容的语句

    太久没有用SQL语句都有些忘记了,今天工作中遇到了那就尝试记录一下吧 需求是这样的:想查询同一个字段下,两条指定了不同内容,的其他的值 主要是要想到用where......in 语句如下:select ...

  4. linux tar 解压命令

    如果提示 common not find 先进行安装如下 wget http://www.rarsoft.com/rar/rarlinux-5.3.0.tar.gz tar -zxvf rarlinu ...

  5. Educational Codeforces Round 51 (Rated for Div. 2) G. Distinctification(线段树合并 + 并查集)

    题意 给出一个长度为 \(n\) 序列 , 每个位置有 \(a_i , b_i\) 两个参数 , \(b_i\) 互不相同 ,你可以进行任意次如下的两种操作 : 若存在 \(j \not = i\) ...

  6. Nifi InvokeHttp processor

    Authorization: Bearer <access-token> Content_type: application/json       NIFI 中国社区 QQ群:595034 ...

  7. zookeeper部署

    版本:zookeeper-3.4.5-cdh5.10.0.tar.gz 网址:http://archive-primary.cloudera.com/cdh5/cdh/5/ 1. 解压 $ tar - ...

  8. htmlunit 校验验证码

    htmlUnit 校验验证码 直接上代码 String url = "http://www.zycg.gov.cn/"; WebclientUtil webClientUtils ...

  9. 洛谷P3321 序列统计

    气死了,FFT了半天发现是NTT... 1004535809 这个东西是NTT模数,原根为3. 题意:给定集合,元素的大小不超过M.用这些元素组成长为n的序列,要求乘积模M为k,求方案数. n < ...

  10. c++ stl sort

    两者相等时,必须为false. 满足拟序. 群里大佬666.