简体   繁体   中英

email body content gets removed when mail sent from crontab

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM