4

RHEL6 In root's crontab a have: * 21 * * * /root/script.sh

In script.sh there is a line: /usr/bin/sudo -u jira bash -c 'cd /opt/jira/bin; ./stop-jira.sh' && echo "Jira Shut Down" >> /root/debuglog

The command executes in a regular shell but not when run from cron.

The cron process works fine and the rest of the script executes correctly, it's just the sudo part that doesn't work.

I have updated the script: swapping out sudo for su and tested in another script and it seems to work. I'll test on the actual script tonight and update this post then.

The sudo to su change corrected the issue.

Thanks

Codefire
  • 43
  • 1
  • 1
  • 5
  • Work your way through the Q&A above. It will help you solve your problem or at least help you gather information that will help us to help you. – user9517 Feb 10 '15 at 06:49
  • Hint: you need to capture the stderr output of the sudo command. – user9517 Feb 10 '15 at 06:53

1 Answers1

4

If the script is running in root's crontab, you should remove 'sudo' from the command. I've seen this before, where trying to 'sudo' when you're already root makes the command fail.

If you want to switch user, then the command when run as root, is 'su -l jira', not sudo -u jira.

LHWizard
  • 546
  • 4
  • 11