Answer the question
In order to leave comments, you need to log in
Bash - How to compare times?
Hello.
There is a need to compare the time of the last editing of the file with the current time of os, how can this be done? That is, let's say we need to check how often the file is filled with information and if it has not been edited for some period of time, then we should receive a notification about this.
Thank you.
Answer the question
In order to leave comments, you need to log in
Checking if a file has been modified more than 20 seconds ago:
f=/tmp/test.txt
if ((`date +%s` - `date +%s -r "$f"` > 20)); then
# do something
fi
Current time date +%s
Edit time stat -c %Z file.log
Subtract the current time from the change and compare the result with the desired number of seconds.Если(результат > желаемого){ шли оповещение }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question