简体   繁体   English

Crontab在Linux上运行Java Shell脚本

[英]Crontab to run a java shell script on linux

Am writing a simple java script to send email it works perfectly however it does work in the crontab. 我正在编写一个简单的Java脚本来发送电子邮件,它可以正常工作,但是在crontab中却可以工作。 the command sh sendmail.sh works 命令sh sendmail.sh有效

Here is my crontab command from crontab -e 这是来自crontab -e的crontab命令

*/5 * * * * sh  user /home/user/classes/sendmail.sh

I expect this to work and send mail every 5 minutes but it doesn't work 我希望它能正常工作,每5分钟发送一次邮件,但它不起作用

However the command sh sendmail.sh works 但是命令sh sendmail.sh works

I need help on the crontab 我需要有关crontab的帮助

thanks guys but I found the solution 谢谢大家,但我找到了解决方案

this code works 此代码有效

*/5 * * * * (cd /home/user/classes; sh mail.sh)

Your correct lines is the following 您的正确行如下

*/5 * * * * user /home/user/classes/sendmail.sh (without "sh" word) */5 * * * * user /home/user/classes/sendmail.sh (不带“ sh”字)

You have to be aware that user "user" has permission to execute the script "sendmail.sh" 您必须注意,用户“ user”有权执行脚本“ sendmail.sh”

You can see that executing ls -la sendmail.sh and reading who is the owner and the permissions. 您可以看到执行ls -la sendmail.sh并读取谁是所有者和权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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