Atualmente tenho arquivo com estrutura como
Foo Sign: blah
SubFoo Sign: blah
BarDate: 2017-11-31
Foo Sign: blah
BarDate: Never
Foo Sign: blah
BarDate: 2016-12-20
Foo Sign: blah
BarDate: 2014-12-20
.... and so on
Estas são as quatro principais categorias de dados que residem no arquivo. Não vá com as coisas foo , bar , blah , essas não são importantes. Principal importante é BarDate e seu valor.
Parte Principal
Caso 1: Se o valor BarDate for Never , não preciso fazer nada.
Caso 2: Se BarDate tiver algum valor diferente de Never , o formato será YYYY-MM-DD .
Requisito: Se o BarDate estiver dentro do período de 10 dias a partir de hoje, enviaremos um e-mail para alguém com seus detalhes.
Portanto, hoje é 15-12-2015 se houver qualquer BarDate , que é de 15 a 25 de dezembro de 2015, um e-mail será enviado com seu Foo Sign , BarDate .
Assim, um e-mail será acionado para 2015-12-16 , 2015-12-24 , 2015-12-25 ...
Mas não para 2014-12-16 , 2016-12-24 , 2015-12-26
Até agora, meu script de shell é
foo=""
bardate=""
outputfile="test.txt"
result=""
newline="\n"
### just a workaround step ###
if [ -f $outputfile ];
then
'rm $outputfile'
fi
### filtering the date which doesn't have BarDate as Never, and writing it to a file ###
'cat datafile | grep -e "Foo Sign" -e BarDate | grep -v "Never" | uniq >> $outputfile'
IFS=$'\n'
### contains is a custom function which returns 1 if param1 is substring of param2 ###
for line in ${cat outputfile};
do
contains "$line" "Foo Sign" && foo="$line"
### constructing the result string ###
### -----> here I have to extract the date and see if it resides within 10 days span from today <----- ###
### then only the result string will be constructed ###
contains "$line" "BarDate" && bardate="$line" && result=$result$newline$foo$newline$bardate$newline
done
### mail the result ###
echo -e "$result" | mailx -s "BLAH" [email protected]