Off-topic:
Do you really want to restart the service every minute?
When the services fails due to some other failure, trying to restart every minute is terrible. (Never delete the test-database...)
(You might make a smarter script that checks for the last failur time and waits at least 1 hour before retrying and mailing an operator)
On-topic:
When you can't depend on the returnvalue of mysql, you can try to select some string:
FLAG="$(mysql --host="localhost" --user="root" --password="password" --database="test" \ --execute="select count(*) as MYSPECIALFLAG from test")" if [[ ${FLAG} != *MYSPECIALFLAG* ]]; then my_restart_function fi
FLAG="$(mysql --host="localhost" --user="root" --password="password" --database="test" \
--execute="select count(*) as MYSPECIALFLAG from test")"
if [[ ${FLAG} != *MYSPECIALFLAG* ]]; then
my_restart_function
fi
Other question: sudo without terminal: Restarting the service is the responsibility of root. The system administrator running root would like to check his own crontab when something is restarting the service every minute. So convince your system administrator that he wants to run your magic script as root, and you do not have problems with sudo.