Run grep on text file every 10 minutes

Discussion in 'Mac Programming' started by bingefeller, Mar 28, 2016.

  1. bingefeller macrumors 6502a

    Jun 25, 2007
    Northern Ireland
    Hi guys,

    I know very little about scripts and programming so how would I go about this..

    I have my IRC log file - /apple/users/Macbookpro/Chat Logs/Rooms/chat.log

    How could I run a script that would run the grep command on that chat.log file to search for imgur links and then download any images that were posted?
  2. robvas macrumors 68030

    Mar 29, 2009
  3. bingefeller thread starter macrumors 6502a

    Jun 25, 2007
    Northern Ireland
  4. Analog Kid macrumors 601

    Analog Kid

    Mar 4, 2003
    On OS X, the preferred method is launchd agents:

    If you write the script you want, or use something like Automator to create one, launchd uses an XML file to tell it how to run it periodically. Or you can use something like Lingon to create the XML for you:

    And if you're new to scripting, I might suggest looking at something like Python to write your script, rather than shell scripting...
  5. moonman239 macrumors 68000

    Mar 27, 2009
    AppleScript looks like a good friend here.
    You can run shell commands using the "do shell script" command.
    Take a look at this script (copied from
    repeat 10 times
       say "Small Guy says Hi!"
       delay 1
    "delay 1" tells the AppleScript interpreter to wait 1 second before continuing.
  6. superscape macrumors 6502a


    Feb 12, 2008
    East Riding of Yorkshire, UK
    I'd strongly recommend the launchd method that Analog Kid mentioned.

    Cron will work, but is the 'old' method and Apple recommends launchd instead. I suspect that means that cron will be deprecated at some point in the future. Whether that happens or not, you'll find launchd much more flexible. There's a good tutorial here:

    The AppleScript method would mean that the script would wait one second after completion of the script before running again. So, if your script took 5 mins to run then the interval would be 5 mins and one second. That may or may not be a problem for you.

Share This Page

5 March 28, 2016