It could be the lateness of the hour, but I can't understand why the following script isn't working. It's directly from the CommuniGate Pro documentation http://www.communigate.com/CGPSophos/#Update, but when I try to run it manually, the echo commands don't echo, and the email never gets sent.

Installation process: copy from web page, sudo pico filename, paste, save, chmod 755.

Everything works fine when I run the commands it calls directly; the problem there is that I want to have these regularly launched by launchd, and the commands only work if they're run as ./commandname from that base directory—no idea how to do that in launchd and Apple docs not helping. (Question will be considered answered if someone tells me how to do this.) [Edit: found the WorkingDirectory key in "man launchd.plist", but help on the shell script thing would still be nifty.]

The script:

MAILER_CMD="/usr/bin/mail -s 'Sophos Update Report'"
( \
if [ "$1" = -m ]; then
 echo "Launching Sophos monthly update..."
 ./monthlyUpdate 2>&1
 ./engineUpdate 2>&1
echo "Launching Sophos daily update..."
  ./dailyUpdate 2>&1
) | eval ${MAILER_CMD} ${REPORT_ADR}
  • Ah... found the WorkingDirectory key in the launchd.plist man page. One problem solved. Would still like to know why the shell script is borked. – Jeff Porten Jan 2 '18 at 10:07
  • I'm confused. You mention that it doesn't work if you run it manually, but you also mention that it does work if you run ./command. And launchd seems to play a role as well (which opens another can of worms). Can we take this step by step and focus on getting the script to run in a shell to start with? Could you rewrite your question accordingly? – nohillside Jan 2 '18 at 10:09
  • The echo don't show in Terminal as there output is sent to mail. Is your mail server configured correctly? Can you replace the eval ${MAILER_CMD} ${REPORT_ADR} part with cat to get everything dumped on screen? – nohillside Jan 2 '18 at 10:11
  • Thanks for the quick response! I'm still editing my question and you're here already. Yes, the problem is that /path/to/script.sh returns a system prompt after maybe a half-second; even if the rest of the commands are problematic, since it's not getting to the echo commands, I'm assuming nothing is happening. ./monthlyUpdate works; ./script.sh does not. – Jeff Porten Jan 2 '18 at 10:13
  • Aha (re "output sent to mail")! Got it, I didn't realize that echo was also being redirected. Yes, entirely possible there's a mail problem, this is a dev server and I haven't tested outbound mail yet. Give me a minute, I'll remove the eval code and try again—that should put it on stdout, right? – Jeff Porten Jan 2 '18 at 10:15

You must log in to answer this question.

Browse other questions tagged .