记录第一次写linux系统上的shell脚本
一.shell实现的任务:
1.将内存使用情况与磁盘使用情况重定向到txt文件
2.将sql查询的昨日统计数据重定向到txt文件
URL=127.0.0.1
PORT=3306
USERNAME=”admin”
PASSWORD=”admin”
DBNAME=”bills”
TABLENAME=”order”
#昨天日期
DATE=`date+”%Y-%m-%d” –d “-24hour”`
SQL=”select DATE_FORMAT{pay_time,’%Y-%m-%d’} as jyrq,count(1) as jyje from order where DATE_FORMAT{pay_time,’%Y-%m-%d’} = ‘${DATE}’ group by DATE_FORMAT{pay_time,’%Y-%m-%d’} ”
#输出昨日日期到txt
echo “日期:” >test.txt
echo ${DATE} >>test.txt
#输出磁盘信息
echo “磁盘信息:” >>test.txt
df –h >>test.txt
#内存使用情况
echo ” 内存使用情况” >>test.txt
free –g >>test.txt
#进程使用数量查看
echo “进程数量:” >>test.txt
ps –ef|grep ybill –c >>test.txt