shell脚本实例总结
2024-08-26 12:40:48
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
最新文章
- 动态添加和更改F7编辑器(div和editGrid列)
- java-类
- CSS元素类型
- Linux命令 ,在当前目录下查找一个,或者多个文件
- iOS 开发者必不可少的 75 个工具,你都会了吗
- NGINX的奇淫技巧 —— 5. NGINX实现金盾防火墙的功能(防CC)
- 李洪强iOS开发之OC[018]对象和方法之间的关系
- 熟悉Git使用
- js验证日期
- Math.floor(Math.random()*3+1)
- 价值1.35亿美元的BUG
- FreeBSD常用操作
- 论文阅读笔记十八:ENet: A Deep Neural Network Architecture for Real-Time Semantic Segmentation(CVPR2016)
- poj2151--Check the difficulty of problems(概率dp第四弹,复杂的计算)
- OPENGL NEHE Lesson11 11课的计算公式推导
- GAutomator,GAutomatorview和Android SDK,Unity配置
- QT开发(十二)——QT事件处理机制
- excel表中同一列相同内容进行合并
- HDU-2665-Kth number(划分树)
- DataBase 之 数据库设计六大范式