[英]I want cron to run a jar file only when it's not already running
So I tried to make cron run a jar file, but I can't figure out how to make it work.所以我试图让 cron 运行一个 jar 文件,但我不知道如何让它工作。 This is what I tried, but nothing happens.
这是我尝试过的,但没有任何反应。 I also ran the line without the * * * * * and there is no output.
我还运行了没有 * * * * * 的行,并且没有输出。 What am I doing wrong?
我究竟做错了什么?
* * * * * sudo /usr/bin/flock -w 0 /run/lock/cron.lock cd /home/opc java (my java file)
I wrote this based on what I read on other questions but I don't have much experience so I need a little more in-depth explanation to get this right.我是根据我在其他问题上阅读的内容写的,但我没有太多经验,所以我需要更深入的解释才能做到这一点。 I didn't create any cron.lock file.
我没有创建任何 cron.lock 文件。 Is that an issue?
这是一个问题吗? I prefer not to run scripts or things, only this 1 command.
我不喜欢运行脚本或其他东西,只运行这 1 个命令。
Thanks!谢谢!
Well I actually fixed it.好吧,我确实修复了它。 My mistake was on not telling the java command where my .jar was the proper way.
我的错误是没有告诉 java 命令我的 .jar 是正确的方法。 Cd didn't work.
cd没用。 Classpath will do the trick better.
Classpath 会做得更好。
* * * * * sudo flock -n /run/lock/cron.lock java -classpath /your/jar/location -jar yourFile.jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.