V
V
Valeriu1472017-05-13 08:46:16
linux
Valeriu147, 2017-05-13 08:46:16

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

But for some reason it doesn't work and I get the second condition. Although I do not have compressed files and I would like to compress them.
This condition works very well:
find /var/log/$name* -type f -print0 -and ! -name "*.gz" -and ! -name "$current_nginx" -exec gzip "{}" \;

But this doesn't work for me a bit, I need to exit the script body, in case I don't have new logs.
How to proceed in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-05-13
@Rsa97

nginx.log. 20170512
data=$(date + %Y.%m.%d )
Don't you think the dots are superfluous?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question