Link to home
Start Free TrialLog in
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.
Avatar of noci
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

Avatar of Amin El-Zein

ASKER

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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i will test it and back to u
thank u so much