Reputation: 2545
I have following command in Ubuntu Linux,
mysql -u root -p"password" "dbname" -e 'select count(*) User_Count from "tableName"' | mail
-s 'Count' "email_id"
When this command is executed from command line it send mail with subject and query output as message body
However if I schedule the same command through crontab - I get email only with subject and message body is empty
Upvotes: 0
Views: 667
Reputation: 9887
That's probably an indicator that mysql is failing to run as specified.
Redirect standard error when you run the command, and you'll at least get an e-mail with the error message telling you what you're missing:
mysql 2>&1 -u root -p -e 'select count(*) User_Count from ' | mail -s 'Count' "email_id"
Also, make sure the directory where mysql resides is either in the PATH, or you specify it manually on the command line.
Upvotes: 4