恭喜你,找到宝藏博主了,这里会分享shell的学习整过程。
shell 对于运维来说是必备技能之一,它可以提高很多运维重复工作,提高效率。
shell的专栏,我会详细地讲解shell的基础和使用,以及一些比较常用的shell技巧。
有需要的可以从这里开始,可以教会你如何去进行shell脚本的编写,提高你的工作效率。
从第一篇基础开始:
【shell脚本】shell脚本之概念、运行方式、变量的使用、交互式脚本、运算(shell脚本基础学习一)_向往风的男子的博客-CSDN博客
关于shell的学习就到这里了,还想系统学习terraform的同学,也可以关注我的terraform专栏学习,大家一起学起来。
ARCHIVE_DATE=`date +"%Y%m%d" -d "-1day"`
# 需要分割的日志文件名绝对路径,可以配置多个
TARGETS="/home/nginx/bin/nlp3/chat_log/log.log"
KEEP_DAYS=3
for target in $TARGETS
do
FILE=`basename $target`
BASEDIR=`dirname $target`
cd $BASEDIR && echo $BASEDIR/$FILE && cat $FILE >> $FILE$ARCHIVE_DATE
tar -czvf $FILE.$ARCHIVE_DATE.tar.gz $FILE.$ARCHIVE_DATE && rm -rf $FILE.$ARCHIVE_DATE && cat /dev/null > $FILE
find "${BASEDIR}" -type f -name "$FILE_*.tar.gz" -mtime +${KEEP_DAYS} -exec rm -rf {} \;
done
·······································
#!/bin/sh
exit 0
dir="/home/nginx/logs/"
delete () {
tag=$1
c=$(ls -v ${dir}/${tag}* | wc -l)
n=`expr $c - 1`
if [ $n -gt 0 ];then
for i in `ls -v ${dir}/${tag}-*.log | head -$n`; do
echo $i;
rm -f $i
done
fi
}
#delete "access"
#delete "error"
log="/home/nginx/work/logs"
now=`date '+%Y-%m-%d'`
cp ${log}/access.log ${dir}/access-$now.log
echo "" > ${log}/access.log
cp ${log}/error.log ${dir}/error-$now.log
echo "" > ${log}/error.log
···································································
#!/bin/bash
#日志目录
LOGS_PATH=/usr/local/nginx/logs
YESTERDAY=$(date --date="yesterday" +%Y-%m-%d)
SEVENDAY=$(date --date="7 days ago" +%Y-%m-%d)
rm -rf ${LOGS_PATH}/error-${SEVENDAY}.log
rm -rf ${LOGS_PATH}/access-${SEVENDAY}.log
mv ${LOGS_PATH}/error.log ${LOGS_PATH}/error-${YESTERDAY}.log
mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access-${YESTERDAY}.log
#重启nginx
#service nginx restart
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
/usr/local/nginx/sbin/nginx -s reload