self-executing terminal commands?

Discussion in 'macOS' started by bpetruzzo, Feb 2, 2010.

  1. bpetruzzo macrumors regular

    Joined:
    Oct 22, 2005
    #1
    I have three simple commands that I need to be able to execute on a regular basis. Opening terminal and doing all that really sounds like it's going to be a pain the butt.

    Is there a simple way to set up something like an automator script that will automatically execute a short string of terminal commands?

    It's basically this:

    cd /applications/SugarCRM
    ./ctlscript.sh start

    That's about it. Is there an easy way to do this?
     
  2. miles01110 macrumors Core

    miles01110

    Joined:
    Jul 24, 2006
    Location:
    The Ivory Tower (I'm not coming down)
    #2
    There's an Automator action called "run shell script" i think.
     
  3. belvdr macrumors 603

    Joined:
    Aug 15, 2005
  4. GoKyu macrumors 65816

    GoKyu

    Joined:
    Feb 15, 2007
    Location:
    New Orleans
    #4
    I'm not sure how you'd run a shell script from the GUI (double click on the file, I would guess...)

    But if you go into terminal, run pico and type:

    Code:
    #!/bin/sh
    /applications/SugarCRM/ctlscript.sh start
    
    Make sure to chmod the file 755 if you want to be able to execute it.

    (chmod 755 <filename>)
     
  5. Denarius macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #5
    You need to let launchd take care of it.

    Here's the plist, set to run every 4 hours (14,400 seconds)

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
            <key>Label</key>
          <string>com.sugarcrm.ctlscript.sh</string>
            <key>ProgramArguments</key>
            <array>
                    <string>/Applications/SugarCRM/ctlscript.sh</string>
                    <string>start</string>
            </array>
            <key>LowPriorityIO</key>
            <true/>
            <key>RunAtLoad</key>
            <false/>
            <key>StartInterval</key>
            <integer>14400</integer>
    </dict>
    </plist>
    
    
    plist belongs in /Library/LaunchAgents/ if you normally run it with administrator rights (sudo or as root) or in ~/Library/LaunchAgents/ if you run it in user space (no sudo and not root)

    Easiest way is to paste that code into Textedit (make sure it's set to plain text before pasting), save it in the root of your user folder as com.sugarcrm.sugarCRM.plist, then it's off to Terminal.

    If you run it sudo normally then go to applications>utilities>termina (and starting from ~/ prompt in terminal)
    Code:
    sudo chown -R root:wheel com.sugarcrm*
    sudo chmod -R 644 com.sugarcrm*
    sudo mv com.sugarcrm.sugarCRM.plist /Library/LaunchAgents/com.sugarcrm.sugarCRM.plist
    
    If you normally run it as a regular user

    Code:
    sudo chown -R [I]yourusername[/I]:staff com.sugarcrm*
    sudo chmod -R 644 com.sugarcrm*
    sudo mv com.sugarcrm.sugarCRM.plist ~/Library/LaunchAgents/com.sugarcrm.sugarCRM.plist
    
    That's all you need, no shell script or anything else.
     
  6. Denarius macrumors 6502a

    Denarius

    Joined:
    Feb 5, 2008
    Location:
    Gironde, France
    #6
    I forgot to mention that if ctlscript.sh needs system-wide access then it belong in /Library/LaunchDaemons, but I suspect that's not the case.
     

Share This Page