A
A
Anatoly2020-07-25 05:32:45
bash
Anatoly, 2020-07-25 05:32:45

How to compare dates of two files?

Need a script to update .gzip files on the server.

There is an array with filenames:

FILES_SITE=(
style.css
scripts.js
sprites.svg
)


We need to find a file from the array and check if a gzip file exists for it, with a date later than the file itself. If not, then create it.
for i in ${FILES_SITE[@]};do
    find /var/www/ -type f -name ${i} | while read -r path; do
        // gzip -c -9 "$i" > "$i.gz";
        // echo $path
    done
done

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CityCat4, 2020-07-26
@Tolly

Well, I usually take the date of the file, convert it to UTC, then also take the date of the second file - and stupidly compare
. Here is a piece of script that I use to update the CRL on the server

# Take last modification date of newly downloaded CRL file as UTC time
_newcrl=`date -r $storedir/$crlfile +%s`

# Take last modification date of stored CRL file as UTC time
_oldcrl=`date -r $cadir/$crlfile +%s`

# When CRL file is missed, install fake file with modification date Jan 1 1970 00:00
if [ ! -f $cadir/$crlfile ]; then
  touch -t 197001010000 $cadir/$crlfile
fi

# If file on CA store is never than file in their own store - we had have
# publish new CRL and must upload it to server
if [ $_newcrl -gt $_oldcrl ]; then
        [тут мы что-то делаем]
fi

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question