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
  • 66,199
  • 35
  • 114
  • 250
Thomas_
  • 11
  • 2
  • 2
    Possible duplicate of [get age of given file](https://unix.stackexchange.com/questions/102691/get-age-of-given-file) – Panki Feb 12 '19 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 '19 at 13:01
  • 1
    @Thomas_ please see the help section on [merging accounts](https://unix.stackexchange.com/help/merging-accounts) – jesse_b Feb 12 '19 at 13:10
  • Are you using Solaris 11, or 10? (or 9 or 8?!?) – Jeff Schaller Feb 12 '19 at 13:28
  • If any of the answers solved your problem, please [accept it](https://unix.stackexchange.com/help/someone-answers) by clicking the checkmark next to it. Thank you! – Jeff Schaller Feb 24 '19 at 14:22

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
  • 66,199
  • 35
  • 114
  • 250
0

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

find /foo -type f  -mmin +5 
Michael D.
  • 2,820
  • 16
  • 24
  • responds with : find: bad option -mmin – Thomas_ Feb 12 '19 at 12:58
  • @Thomas_ If the default Solaris `find` doesn't support `-mmin`, maybe you can install GNU `find`? (https://www.opencsw.org/packages/findutils/) – Bodo Feb 12 '19 at 13:19
  • @Thomas_ Are you using `/usr/bin/find` by default? Try `/usr/xpg4/bin/find` instead. – Kusalananda Feb 12 '19 at 13:25
  • 2
    [newer Solaris](https://docs.oracle.com/cd/E26502_01/html/E29030/find-1.html) do have -mmin in the xpg4 version; Solaris 10: no; Solaris 11: yes – Jeff Schaller Feb 12 '19 at 13:27