1

I have a bash script on a Solaris server to provide an alert if a file is in a folder location for longer than 5 minutes.

if [ -f $1 ]
then
a=0
else
a=1

However, it is throwing a lot of false positives so I need to know how to add an additional filter when looking for a file to anything which was modified / created longer than 5 minutes ago.

If a file in x folder location is older than 5 minutes, I would like the script to report that.

This question is not the same as the "possible duplicate" as I am requesting assistance with Solaris Linux and that ticket is referencing MAC and Linux, the commands mentioned there are not working in my Solaris box!

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Thomas_
  • 11

2 Answers2

2

You can work around it by manually creating a temporary file that's dated to five minutes ago, then ask find for files that are not newer than your temporary file:

tempfile=$(mktemp)
if [ "$?" -ne 0 ]
then
  echo "Error creating temporary file; exiting"
  exit 1
fi
touch -t $(( $(date  +%Y%m%d%H%M) - 5 )) "$tempfile"
find /your/path -type f ! -newer "$tempfile"
rm "$tempfile"
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
0

Find all files in /foo which are older than 5minutes

find /foo -type f  -mmin +5 
Michael D.
  • 2,830