Avatar of Amin El-Zein
Amin El-Zein
 asked on

freebsd system search and do command automaticly

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.
System ProgrammingSystem UtilitiesFreeBSD

Avatar of undefined
Last Comment
Amin El-Zein

8/22/2022 - Mon
noci

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

Amin El-Zein

ASKER
for example: 2018-11-21
ASKER CERTIFIED SOLUTION
noci

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Amin El-Zein

ASKER
i will test it and back to u
thank u so much
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck