简体   繁体   English

我希望 cron 仅在尚未运行时运行 jar 文件

[英]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.

相关问题 安排cron条目仅在尚未运行时运行脚本 - Schedule cron entries to run script only when not already running 仅当 cron 作业尚未运行时才运行它 - Run cron job only if it isn't already running 为什么要运行Coffeescript cake命令时为什么最终运行CakePHP的cake命令? - Why do I end up running CakePHP's cake command when I want to run the Coffeescript cake command? Python 脚本没有在 cron 下运行,尽管在手动运行时可以工作 - Python script is not running under cron, despite working when run manually 在Ubuntu中,我怎样才能从终端打开应用程序,只有它还没有运行? - In Ubuntu, how might I from the terminal open application only if it's not already running? 仅当 AIDE 检测到文件修改时,我如何才能获得 email 我的 cron? - How do I get cron to email me only when AIDE detects file modification? 仅在机器空闲时运行cron作业(linux) - run cron job only when machine is idle (linux) Moodle 2.5(openSuse)cron作业停止运行,我找不到它,或者记录了一下,Moodle的cron在哪里? - Moodle 2.5 (openSuse) cron job stopped running, I can't find it, or logs, where is Moodle's cron? SSH进入但不是通过cron时,运行PHP文件可以正常工作 - Running PHP file works correctly when SSH'd in but not via cron 从cron运行时,Perl脚本不会将STDOUT输出到文件 - Perl script does not output STDOUT to file when run from cron
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM