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
05-08 15:02