If the File is Older Than the Specified Date, Do Something in Shell Script

Shellscript(Bash/Zsh)
2022-05-28 16:29 (2 years ago) ytyng

This script is written to check for tasks that have not been processed for a certain period of time and to trigger an alert when you open the terminal on a Mac.

date -r <target-file-path> +"%s"

↑ You can get the Unix timestamp (epoch seconds) of a file, so use this for calculation.

#!/usr/bin/env zsh
# Alert if a certain amount of time has passed since the last processing

cd "$(dirname $0)" || exit

now=$(date "+%s")
file_timestamp=$(date -r <target-file-path> +"%s")
delta=$(($now - $file_timestamp))

threshold=$((86400 * 35))
# echo "delta = ${delta}"
# echo "threshold = ${threshold}"

if [ ${delta} -gt ${threshold} ]; then
echo "More than 35 days have passed since the last processing."
echo "Please perform the necessary processing."
fi
Currently unrated

Archive

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011