发送统计邮件shell脚本
#!/bin/bash
#作者:Presley
#时间:2018.07.16
#监控阿里云aaa库的py_weixin_product_close_rating_info 和 py_weixin_product_open_rating_info两个表当天记录条数和前一天记录条数
source /etc/profile #加载系统环境变量
source ~/.bash_profile #加载用户环境变量
set -o nounset #引用未初始化变量时退出
user="aaa"
port="3306"
password="aaa"
database="aaa"
today="$(date +%Y-%m-%d)"
yesterday="$(date +%Y-%m-%d --date="-1 day")"
host="aaa"
send_mail_name=("lipingchang@pystandard.com" "weijiyao@pystandard.com" "songchuwen@pystandard.com" "linfumei@pystandard.com" "denglei@pystandard.com")
#表py_weixin_product_close_rating_info当天数据条数sql
sql_tableclose_today_count="select count(*) from py_weixin_product_close_rating_info where report_date='${today}';"
#表py_weixin_product_close_rating_info前一天数据条数sql
sql_tableclose_yesterday_count="select count(*) from py_weixin_product_close_rating_info where report_date='${yesterday}';"
#表py_weixin_product_open_rating_info当天数据条数统计sql
sql_tableopen_today_count="select count(*) from py_weixin_product_open_rating_info where report_date='${today}';"
#表py_weixin_product_open_rating_info前一天数据统计条数sql
sql_tableopen_yesterday_count="select count(*) from py_weixin_product_open_rating_info where report_date='${yesterday}';"
mysqlconn="/application/mysql/bin/mysql -u${user} -p${password} -h${host} -P${port} -D${database} -e"
#将当天和前一天的记录条数统计
num_close_today=$(${mysqlconn} "${sql_tableclose_today_count}" 2>/dev/null | sed '1d')
num_close_yesterday=$(${mysqlconn} "${sql_tableclose_yesterday_count}" 2>/dev/null | sed '1d')
#将当天和前一天的记录条数统计
num_open_today=$(${mysqlconn} "${sql_tableopen_today_count}" 2>/dev/null | sed '1d')
num_open_yesterday=$(${mysqlconn} "${sql_tableopen_yesterday_count}" 2>/dev/null | sed '1d')
function send_mail()
{
echo "1、封闭式表:
${today}日 统计记录条数为: ${num_close_today} 条;
${yesterday}日 统计记录条数为: ${num_close_yesterday} 条。
2、开放式表:
${today}日 统计记录条数为: ${num_open_today} 条;
${yesterday}日 统计记录条数为: ${num_open_yesterday} 条。" | mail -s "表记录统计结果" $1
}
#发送邮件
for name in ${send_mail_name[@]}
do
send_mail $name
done
发送统计邮件shell脚本的更多相关文章
- zabbix 4.2 发送警告邮件Python脚本
#!/usr/bin/env python#-*- coding: UTF-8 -*-import os,sysimport getoptimport smtplibfrom email.MIMETe ...
- 【python】脚本连续发送QQ邮件
今天习得用python写一个连续发送QQ邮件的脚本,经过测试,成功给国内外的服务器发送邮件,包括QQ邮箱.163邮箱.google邮箱,香港科技大学的邮箱和爱丁堡大学的邮箱.一下逐步解答相关技巧. 首 ...
- shell脚本安装部署反向代理 监控进程 计划任务
1.编写脚本自动部署反向代理.web.nfs: 要求: I.部署nginx反向代理三个web服务,调度算法使用加权轮询: 反向代理服务器脚本配置脚本 #!/bin/bash #安装eple和nginx ...
- zabbix邮件告警之 通过shell脚本发送告警
说明:本文讲如何通过shell脚本实现zabbix发送告警邮件,共有5步1.设置mailx账号:是配置mailx的发信账号2.zabbix服务器端编写邮件发送脚本:是增加zabbix的告警方式,增加通 ...
- [linux] shell脚本编程-统计日志文件中的设备号发通知邮件
1.日志文件列表 比如:/data1/logs/2019/08/15/ 10.1.1.1.log.gz 10.1.1.2.log.gz 2.统计日志中的某关键字shell脚本 zcat *.gz|gr ...
- Git学习-->如何通过Shell脚本实现 监控Gitlab备份整个过程并且通过邮件通知得到备份结果?
一.背景 Git学习–>如何通过Shell脚本自动定时将Gitlab备份文件复制到远程服务器? http://blog.csdn.net/ouyang_peng/article/details/ ...
- shell脚本编程学习笔记(三)编写邮件报警脚本
一.shell编写邮件报警脚本 1.POSTFIX邮件服务器准备 a.首先卸载服务器上自带的sendmail rpm -qa sendmail* //查看安装的sendmail rpm -e send ...
- shell脚本实现网站日志分析统计
如何用shell脚本分析与统计每天的访问日志,并发送到电子邮箱,以方便每天了解网站情况.今天脚本小编为大家介绍一款不错的shell脚本,可以实现如上功能. 本脚本统计了:1.总访问量2.总带宽3.独立 ...
- 利用shell脚本统计文件中出现次数最多的IP
比如有如下文件test.txt 1 134.102.173.43 2 134.102.173.43 3 134.102.171.42 4 134.102.170.9 要统计出现次数最多的IP可 ...
随机推荐
- 【刷题】BZOJ 4946 [Noi2017]蔬菜
Description http://www.lydsy.com/JudgeOnline/upload/Noi2017D2.pdf Solution 网上大部分都是并查集写法,但是有大神写了非并查集写 ...
- BZOJ 2427 [HAOI2010]软件安装 | 这道树形背包裸题严谨地证明了我的菜
传送门 BZOJ 2427 题解 Tarjan把环缩成点,然后跑树形背包即可. 我用的树形背包是DFS序上搞的那种. 要注意dp数组初始化成-INF! 要注意dp顺推的时候也不要忘记看数组是否越界! ...
- idea问题总结记录
1.部署tomcat后,tomcat日志报错:java.lang.ClassNotFoundException 1.1 原因: tomcat虽然部署成功,但是并没有把本项目中访问服务器所需的类库加到W ...
- java绘图合并图像AlphaComposite模式测试
package com.hdwang.test; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.sw ...
- D. Recovering BST Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
http://codeforces.com/contest/1025/problem/D 树 dp 优化 f[x][y][0]=f[x][z][1] & f[z+1][y][0] ( gcd( ...
- HDU 6181 第k短路
Two Paths Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 153428/153428 K (Java/Others)Total ...
- kubespray 一键安装k8s集群
1. clone代码 git clone https://github.com/kubernetes-incubator/kubespray.git 2. 添加inventory/inventory ...
- python3中__get__,__getattr__,__getattribute__的区别
__get__,__getattr__和__getattribute都是访问属性的方法,但不太相同. object.__getattr__(self, name) 当一般位置找不到attribute的 ...
- Python 算法实现
# [程序1] # 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? l=[1,2,3,4] count = 0 for i in range(len(l)): fo ...
- html5 canvas 弧形描边渐变
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...