1.判断文件夹是否存在

#!/bin/sh

workspace="/home/web/mall"

#如果文件夹不存在
if [ ! -d ${workspace} ]; then
  echo "is not exists"
else
  echo "is exists"
fi

 2.切分nginx日志

 1 #!/bin/bash
 2 #function:cut nginx log files for lnmp v0.5 and v0.6
 4 
 5 #set the path to nginx log files
 6 log_files_path="/home/www/wwwlogs/"
 7 backup_files_path="/alidata1/logs/nginx/"
 8 
 9 
10 log_files_dir=${backup_files_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/$(date -d "yesterday" +"%d")
11 
12 if [ ! -d ${log_files_dir} ]; then
13   mkdir -p $log_files_dir
14 fi
15 
16 #set nginx log files you want to cut
17 log_files_name=(access nginx_error wechat.51ekt.com mall.51ekt.com shop.51ekt.com api.51ekt.com.log)
18 #set the path to nginx.
19 nginx_sbin="/usr/local/nginx/sbin/nginx"
20 #Set how long you want to save
21 save_days=30
22 
23 ############################################
24 #Please do not modify the following script #
25 ############################################
26 
27 log_files_num=${#log_files_name[@]}
28 
29 
30 #cut nginx log files
31 for((i=0;i<$log_files_num;i++));do
32 log=${log_files_path}${log_files_name[i]}.log
33 if [ -f ${log} ];then
34 mv ${log_files_path}${log_files_name[i]}.log ${log_files_dir}/${log_files_name[i]}_$(date -d "yesterday" +"%Y%m%d").log
35 fi
36 done
37 
38 #delete 30 days ago nginx log files
39 #find $log_files_path -mtime +$save_days -exec rm -rf {} \; 
40 
41 $nginx_sbin -s reload

 

posted on 2018-04-09 19:14  睡着的糖葫芦  阅读(253)  评论(0编辑  收藏  举报