Answer the question
In order to leave comments, you need to log in
Why does the condition for checking the file extension and checking the file name with the current date not work?
Good afternoon. My logs are written in the format nginx.log.2017.05.12, i.e. log and date to it.
I wrote a script that does not archive logs that are already archived and does not archive logs with the current date.
name="nginx.log"
data=$(date +%Y.%m.%d)
current_nginx=$name.$data
cd /var/log/
for i in `ls "$name*"`; do
if && ; then
gzip $i
echo "make compressing for $i"
fi
echo "there are not available nginx logs. stop the script executing"
exit 1
done
find /var/log/$name* -type f -print0 -and ! -name "*.gz" -and ! -name "$current_nginx" -exec gzip "{}" \;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question