shell脚本实例总结
1.判断文件夹是否存在
#!/bin/sh workspace="/home/web/mall" #如果文件夹不存在
if [ ! -d ${workspace} ]; then
echo "is not exists"
else
echo "is exists"
fi
2.切分nginx日志
#!/bin/bash
#function:cut nginx log files for lnmp v0. and v0. #set the path to nginx log files
log_files_path="/home/www/wwwlogs/"
backup_files_path="/alidata1/logs/nginx/" log_files_dir=${backup_files_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/$(date -d "yesterday" +"%d") if [ ! -d ${log_files_dir} ]; then
mkdir -p $log_files_dir
fi #set nginx log files you want to cut
log_files_name=(access nginx_error wechat.51ekt.com mall.51ekt.com shop.51ekt.com api.51ekt.com.log)
#set the path to nginx.
nginx_sbin="/usr/local/nginx/sbin/nginx"
#Set how long you want to save
save_days= ############################################
#Please do not modify the following script #
############################################ log_files_num=${#log_files_name[@]} #cut nginx log files
for((i=;i<$log_files_num;i++));do
log=${log_files_path}${log_files_name[i]}.log
if [ -f ${log} ];then
mv ${log_files_path}${log_files_name[i]}.log ${log_files_dir}/${log_files_name[i]}_$(date -d "yesterday" +"%Y%m%d").log
fi
done #delete days ago nginx log files
#find $log_files_path -mtime +$save_days -exec rm -rf {} \; $nginx_sbin -s reload
shell脚本实例总结的更多相关文章
- 分享7个shell脚本实例--shell脚本练习必备
概述 看多shell脚本实例自然就会有shell脚本的编写思路了,所以我一般比较推荐看脚本实例来练习shell脚本.下面分享几个shell脚本实例. 1.监测Nginx访问日志502情况,并做相应动作 ...
- shell脚本实例,通向shell脚本大师的必经之路
概述 读书百遍其义自见,shell脚本也是,只要例子看得多了,自然就知道怎么写了.这里主要整理了20几个例子,因为内容比较多,所以分了几次来做介绍了.下面的实例最好先自己思考怎么去实现,然后再看下实现 ...
- shell脚本实例-系统监控
shell脚本监控网站并实现邮件.短信报警shell进程监控脚本(发送邮件报警)Shell脚本监控服务器在线状态和邮件报警的方法 http://www.jbxue.com/jb/shell/ 11. ...
- shell脚本实例
备注:一些与传递给shell的参数相关的变量:$# 命令行参数的个数$? 调用命令的返回值$$ 当前进程的进程号$! 最后一个后台命令的进程号$0 命令行的第一个参数,也就是命令名$n 命令行的第n个 ...
- shell脚本实例一,移动文件夹中大于2000B的文件到另一个文件夹
shell脚本能帮我们简化linux下的一些工作,现在有个需求,把TMPA文件夹下大于2000B的文件都移动到TMPB下 #! /bin/bash function movefiles() { ` d ...
- shell脚本实例一
一. 什么是shell 脚本时一种解释性语言: shell脚本保存执行动作: 脚本判定命令的执行条件 脚本来实现动作的批量执行.二.如何创建 vim test.sh ##shell脚本一般都 ...
- shell脚本实例-mysql多机部署
今天我给大家分享shell 安装mysql 多机部署的实例,本次实验是基于各个主机的公钥已经配置好了,如果还不会推送公钥的同学,可以看看我以前写的文章,那里面有写推公钥的实例,mysql 多机部署一般 ...
- shell脚本实例-菜单样例
1.9.1 实例需求 用户在进行Linux系统管理的过程中,经常需要用到查看进程的信息.用户的信息等常用的功能.本例针对这一需求,使用shell编程实现基本的系统管理 功能.通过本程序,可以按照要求实 ...
- shell脚本实例(2)
1.传给脚本一个参数:目录,输出该目录中文件最大的,文件名和文件大小 #!/bin/bash if [ $# -ne 1 -o ! -d $1 ];then echo "Args is er ...
- 【shell脚本实例】一个恶作剧—— kill掉占用CPU较高的matlab进程
我们实验室有台服务器,博士们在服务器上跑MATLAB,基本都是4核都是超过95%的CPU占用,想了个恶作剧的shell 定时kill掉MATLAB程序,是不是很邪恶啊,哈哈~~~ 不过我只是干过一次 ...
随机推荐
- Packets 1037A(二进制数)
分析:看这个数有多少位二进制数 #include<cstdio> int main() { int n; while(~scanf("%d",&n)) { ; ...
- Unity 菜单拓展
添加自定义菜单项 [MenuItem("test/item1 %g")] public static void haha() { Debug.Log("this is a ...
- mysql 设置多个字段聚合自增
DROP TEMPORARY TABLE IF EXISTS ttp_firstInvest; CREATE TEMPORARY TABLE ttp_firstInvest ( userid varc ...
- LeetCode OJ 19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- 微信定时获取token
为了使第三方开发者能够为用户提供更多更有价值的个性化服务,微信公众平台开放了许多接口,包括自定义菜单接口.客服接口.获取用户信息接口.用户分组接口.群发接口等,开发者在调用这些接口时,都需要传入一个相 ...
- 0 开发的准备工作一一虚拟机virturalbox
https://www.virtualbox.org/wiki/Linux_Downloads官网下载linux版本 https://www.ubuntu.com/desktop/developers ...
- Structs复习 Action传递参数
Structs传递参数通常有三种方式 下面我来一个个介绍 1.属性 Jar包 web.xml <?xml version="1.0" encoding="UTF-8 ...
- VC++ 中ListCtrl经验总结
先注明一下,这里,我们用m_listctrl来表示一个CListCtrl的类对象,然后这里我们的ListCtrl都是report形式,至于其他的如什么大图标,小图标的暂时不讲,毕竟report是大众话 ...
- javascript原型链中 this 的指向
为了弄清楚Javascript原型链中的this指向问题,我写了个代码来测试: var d = { d: 40 }; var a = { x: 10, calculate: function (z) ...
- base64 压缩图片
//图片处理 afterimg(err, photos) { var _this = this; if(err && err != null && err != '') ...