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!

  • 2
    Possible duplicate of get age of given file – Panki Feb 12 at 12:18
  • @Panki I am using Solaris which seems to have a different command set - that's why it is not the same as that ticket, thank you for linking though, interesting stuff – Thomas_ Feb 12 at 13:01
  • 1
    @Thomas_ please see the help section on merging accounts – Jesse_b Feb 12 at 13:10
  • Are you using Solaris 11, or 10? (or 9 or 8?!?) – Jeff Schaller Feb 12 at 13:28
  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you! – Jeff Schaller Feb 24 at 14:22
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"
0

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

find /foo -type f  -mmin +5 
  • responds with : find: bad option -mmin – Thomas_ Feb 12 at 12:58
  • @Thomas_ If the default Solaris find doesn't support -mmin, maybe you can install GNU find? (opencsw.org/packages/findutils) – Bodo Feb 12 at 13:19
  • @Thomas_ Are you using /usr/bin/find by default? Try /usr/xpg4/bin/find instead. – Kusalananda Feb 12 at 13:25
  • 2
    newer Solaris do have -mmin in the xpg4 version; Solaris 10: no; Solaris 11: yes – Jeff Schaller Feb 12 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.