Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bpetruzzo

macrumors regular
Original poster
Oct 22, 2005
102
0
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?
 
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>)
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.