Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • The question seems to be wrong. The if...else is obviously working. Your question is: Why does the mysql command not exit with code 0? You should make the second question a separate question as they are not related. Commented Apr 24, 2014 at 8:40
  • @Hauke Laging, thanks, so where is the problem? why the else part also working? Commented Apr 24, 2014 at 8:43
  • You seem to be running the cronjob with root (considering your 2nd question). You don't need the sudo then. Just remove "/usr/bin/sudo" in front of the service calls. It should save you from the TTY problem of sudo. Commented Apr 29, 2014 at 22:43
  • @0xAF, Now first i doubt crontab connect mysql is wrong, because even the server is run well, it still jump into else case, echo "error $(date)" >> /home/myspace/restart_log.txt. but it works directly in SSH part. thanks. Commented Apr 30, 2014 at 6:23
  • try changing this line: RESULT=`mysql --host="localhost" --user="root" --password="password" --database="test" --execute="select browser from test limit 1"`, to this: RESULT=`mysql --host="localhost" --user="root" --password="password" --database="test" --execute="select browser from test limit 1" 1>/tmp/mysql.debug 2>&1` and see the output in /tmp/mysql.debug Commented Apr 30, 2014 at 10:08