[英]email body content gets removed when mail sent from crontab
I have following command in Ubuntu Linux, 我在Ubuntu Linux中有以下命令,
mysql -u root -p"password" "dbname" -e 'select count(*) User_Count from "tableName"' | mysql -u root -p“密码”“ dbname” -e'从“ tableName”中选择count(*)User_Count' mail
邮件
-s 'Count' "email_id" -s'计数'“ 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 但是,如果我通过crontab安排相同的命令-我只会收到主题和邮件正文为空的电子邮件
That's probably an indicator that mysql is failing to run as specified. 这可能表明mysql无法按照指定的方式运行。
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. 另外,确保mysql所在的目录位于PATH中,或者您在命令行上手动指定它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.