M
M
Mikklosh2017-04-18 15:16:34
bash
Mikklosh, 2017-04-18 15:16:34

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

3 answer(s)
X
xibir, 2017-04-18
@Mikklosh

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

D
display: block, 2017-04-18
@qork

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.
Если(результат > желаемого){ шли оповещение }

S
Saboteur, 2017-04-18
@saboteur_kiev

You can simply use find to find files that have been updated more than xx days ago.

for FILE in `find ./* -mtime +30`
do
  echo $FILE
done

and do whatever you want with the list.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question