Run grep on text file every 10 minutes

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

  1. bingefeller macrumors 6502

    Joined:
    Jun 25, 2007
    Location:
    Northern Ireland
    #1
    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 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #2
  3. bingefeller thread starter macrumors 6502

    Joined:
    Jun 25, 2007
    Location:
    Northern Ireland
    #3
  4. Analog Kid macrumors 601

    Analog Kid

    Joined:
    Mar 4, 2003
    #4
    On OS X, the preferred method is launchd agents:
    http://launchd.info

    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:
    https://www.peterborgapps.com/lingon/

    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

    Joined:
    Mar 27, 2009
    #5
    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 http://macscripter.net/viewtopic.php?id=39724):
    Code:
    repeat 10 times
       say "Small Guy says Hi!"
       delay 1
    endrepeat
    
    "delay 1" tells the AppleScript interpreter to wait 1 second before continuing.
     
  6. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #6
    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:

    http://nathangrigg.net/2012/07/schedule-jobs-using-launchd/

    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