Ad Widget

Collapse

Monitor file movement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jro123
    Junior Member
    • Aug 2019
    • 3

    #1

    Monitor file movement

    We have an application that creates a file as soon as an event has occurred. The files are uploaded every minute to a 3rd party server so the files should not exist longer than 1 or 2 minutes.

    how can I create a trigger that will check every so often if there are files in the folder that are older than let's say 10 minutes

    I am trying to create a trigger based on the subject below. The difference is that this is about a log that you expect to change. Our application always has new files (or just none)


    File names are always formatted the same, only the number of characters can change.
    4 letters_1-9charchaters_1-9characters.xml
    Ex. abcd_1234_123456789.xml or abcd_12345_123.xml
    The first 4 letters are always the same.
  • 1berto
    Senior Member
    • Sep 2018
    • 182

    #2
    1) I can't try it now but what happens if you give vfs.file.time a directory (assuming that all the files you want to check will be on the same directory?
    2) If you can use sytem.run: sytem.run[ stat -c $'%y' /path/ | sort -nr | head -1 ] will bring the date of the newer modified file (you cant use another command to get creation date or any other date you want)
    3) You can create an UserParameter calling a script or a command similar to item 2

    Check the documentation for system.run and/or UserParameter

    Comment

    • jro123
      Junior Member
      • Aug 2019
      • 3

      #3
      If it is a folder it will check the date of the folder. If there are no changes, a warning will be sent if the time has elapsed, so no solution. Have looked at all kinds of variants but none that do what I expect.

      Anyway, have written a script that does what I want.
      It basically counts the files in a folder that are older than $AGE and when it's more or equal than 1 it sends an e-mail.


      #!/bin/bash

      # Variables
      AGE=10
      FILEDIR="/path/to/folder/"
      NODE=`/bin/uname -n`
      MAILTO="[email protected]"
      MAILSUBJECT="Ghost file detected"
      MAILBODY="File in ${FILEDIR} more than ${AGE} minutes old"
      MAILFROM="[email protected]"
      MAILFILE="/path/to/mail.txt"

      ### BEGIN SCRIPT
      AGEDCOUNT=0
      ERRORLEVEL=0
      ### Gathering information

      AGEDCOUNT=`/usr/bin/find -L ${FILEDIR} -maxdepth 2 -type f -mmin +${AGE} | /usr/bin/wc -l`

      ### Processing

      if [ "${AGEDCOUNT}" -ge "1" ] ; then
      ERRORLEVEL=1
      else
      ERRORLEVEL=0
      fi

      if [ "${ERRORLEVEL}" -eq "1" ] ; then

      ### Mail Notification

      echo "To: ${MAILTO}" > ${MAILFILE}
      echo "Subject: ${MAILSUBJECT}" >> ${MAILFILE}
      echo "Error detected on ${NODE}" >> ${MAILFILE}
      echo ${MAILBODY} >> ${MAILFILE}
      /usr/bin/find -L ${FILEDIR} -maxdepth 2 -type f >> ${MAILFILE}
      /usr/sbin/sendmail -f ${MAILFROM} -t < ${MAILFILE}

      fi

      Comment

      Working...