Hi Community!
Following on from this code in another thread:
#!/bin/bash
file_string=`/bin/cat date.txt | /usr/bin/awk '{print $5,$4,$7,$6,$8}'`
file_date=`/bin/date -d "$file_string"`
file_epoch=`/bin/date -d "$file_string" +%s`
now_epoch=`/bin/date +%s`
if [ "$file_epoch" -gt "$now_epoch" ]
then
#let difference=$file_epoch-$now_epoch
difference=`/usr/bin/expr $file_epoch - $now_epoch`
elif [ "$now_epoch" -gt "$file_epoch" ]
then
#let difference=$now_epoch-$file_epoch
difference=`/usr/bin/expr $now_epoch - $file_epoch`
else
let difference=0
fi
if [ "$difference" -ge "172800" ]
then
echo "More than 2 days between $file_date and now"
else
echo "Less than 2 days between $file_date and now"
fi
The code above works with the following input file:
$ cat date.txt
Not After : Jul 28 14:09:57 2017 GMT
$ ./script.sh
More than 2 days between Fri 28 Jul 15:09:57 BST 2017 and now
$
But my target file just contains a date such as "10/02/2020"
I'm looking for a way to check if dates listed within a file are greater than 1 year.
The thread above is very close but the date format is not my use case.
What is the best way to achieve this?
Thanks in advance!