freebsd system search and do command automaticly

Amin El-Zein
Amin El-Zein used Ask the Experts™
on
hello
I have a file name info.txt under /etc/
this file contain four lines the fourth line have expiration:data
I want to check this data if it's today+10Days then create a new file name:done.txt and contain done.
else do noting.
thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
nociSoftware Engineer
Distinguished Expert 2018

Commented:
How is the data formatted? ISO 8601 dates  i hope.....
(ISO date=  YYYYMMDDTHHMM  optionaly added seconds and more smaller fractions...)

#!/bin/bash

isodate=$( grep 'expiration:' info.txt | sed -s 's/expiration://' )
edate=${isodate%T*}
expdate=$( date +%4Y%m%d --date='+ 10 days' )
if [ "$expdate" -eq "$edate" ]
then
        echo "done" >done.txt
fi

Open in new window

Author

Commented:
for example: 2018-11-21
Software Engineer
Distinguished Expert 2018
Commented:
Then it can be:
#!/bin/bash

isodate=$( grep 'expiration:' info.txt | sed -s 's/expiration://' )
edate=${isodate%T*}
expdate=$( date +%4Y-%m-%d --date='+ 10 days' )
if [ "$expdate" -eq "$edate" ]
then
        echo "done" >done.txt
fi

Open in new window

Author

Commented:
i will test it and back to u
thank u so much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial