What is the Best Way to Perform Timestamp Comparison in Bash

By far the easiest is to store time stamps as modification times of dummy files. GNU touch and date commands can set/get these times and perform date calculations. Bash has tests to check whether a file is newer than (-nt) or older than (-ot) another.

For example, to only send a notification if the last notification was more than an hour ago:

touch -d '-1 hour' limit
if [ limit -nt last_notification ]; then
    #send notification...
    touch last_notification
fi

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)