I want to compare current date to date present in file [every 30 seconds and in background]
I don't know if I have to do an infinite loop or a while read line loop ...
So, every match of current date with a date of a file, I print the current line matched in xmessage.
( I add a date using ./script.sh 0138 test )
The date is 0138 in this form : +%H%M.
I already tried this but my loop works only one time for the first date in file. Only one window of xmessage is opened... How can this work for each date added ?
while true
do
currentDate="$(date +%H%M)"
futureDate="$(cat test.txt | cut -d ' ' -f 1 | grep "${currentDate}" | head -n 1)"
printLine="$(cat test.txt | grep "${currentDate}")"
if test "${currentDate}" = "${futureDate}"
then
xmessage "${printLine}" -buttons Ok -geometry 400x100 -center
fi
sleep 30
done &
Exemple of file : test.txt
0142 test xmessage
0143 test other xmessage
0144 other test
0145 other xmessage !
Thanks for helping me !
question from:
https://stackoverflow.com/questions/65545621/problem-while-loop-to-compare-current-date-to-date-in-a-file 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…