linux 记录写过的 shell 脚本

一、

[root@manager-117 newjoinslogs]# cat savelog.sh
#!/bin/bash

#funciton: This script is used to save the logs of each service in docker, Then crontab task calls the script at 00:01 a day to save the yesterday's log, And delete logs 15 days ago.
#author: syztoo
#date: 2019-04-15

#yesrq=`date +%F`
yesrq=`date -d "yesterday" +%F`
byqrq=`date -d "15 days ago" +%F`
dcsvs=`docker service ls | awk 'NR>1{print $2}'`

for dcsv in $dcsvs;do
[ ! -d "$dcsv" ] && mkdir "$dcsv"
timeout 5 docker service logs --since="${yesrq}T00:00:01" $dcsv > ./$dcsv/${dcsv}_${yesrq}.log 2> ./$dcsv/${dcsv}_${yesrq}.err
rm -f ./$dcsv/${dcsv}_${byqrq}*
done

 

你可能感兴趣的:(linux 记录写过的 shell 脚本)