发表于: 2016-02-23 00:49:22

1 852


第62天

今天完成的事情:把年前需要做的统计任务的脚本写完并验证,学习了postfix服务器的搭建配置和相关指令的使用。

思路:因为数据库里面保存的数据都是以时间戳的形式保存的,所以:1经行时间戳的转换 2 使用select语句做比较取数据 3将取出来的数据放在一个文件内,写邮件时取出 4设置定时任务

按照上述思路写出来的脚本

#!/bin/bash                                                   #取出数据的脚本
if [ -f "/var/lib/mysql/hell.txt" ]; then
rm -f /var/lib/mysql/hell.txt
echo "delete /var/lib/mysql/hell.txt" >> hell.txt
fi
mysql -uarthur -parthur <<EOF
use carjn;
SELECT COUNT(id) FROM saler  Where  date_format(from_unixtime(create_at/1000),'%Y-%m-%d') =date_format(now(),'%Y-%m-%d') INTO OUTFILE '/var/lib/mysql/hell.txt';
EOF
if [ -f "/var/lib/mysql/indent.txt" ]; then
rm -f /var/lib/mysql/hell.txt
echo "delete /var/lib/mysql/indent.txt" >> hell.txt
fi
mysql -uarthur -parthur <<EOF
use carjn;
 SELECT COUNT(id) FROM indent Where  date_format(from_unixtime(create_at/1000),'%Y-%m-%d') =date_format(now(),'%Y-%m-%d')INTO OUTFILE '/var/lib/mysql/indent.txt';
EOF

发送邮件的脚本

#!/bin/bash 

echo "今天的人数为:`cat /var/lib/mysql/hell.txt` 今天的销售额为:`cat /var/lib/mysql/index.txt`"|mail -s "test" 12345678@qq.com


遇到的问题:

跟大师兄讨论完后,准备简化这个脚本,但是简化后的脚本执行的时候一直在报错,尝试了好的修改还是不行,老大帮我看看。

#!/bin/bash                                                                                                                                     
mysql -uarthur -parthur<<EOF                                                                                                                    
use carjn;                                                                                                                                      
hello=`SELECT COUNT(id) FROM saler  Where  date_format(from_unixtime(create_at/1000),'%Y-%m-%d') < date_format(now(),'%Y-%m-%d')`;              
EOF                                                                                                                                             
echo "今天注册的人数为:$hello"|mail -s "test" 12345678@qq.com

错误提示为:

    test2.sh: 1: test2.sh: SELECT: not found
ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'hello=' at line 1

收获:postfix服务器的搭建配置, mail指令的使用,  nginx错误的排查


返回列表 返回列表
评论

    分享到