简体   繁体   中英

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. 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. Is that an issue? I prefer not to run scripts or things, only this 1 command.

Thanks!

Well I actually fixed it. My mistake was on not telling the java command where my .jar was the proper way. Cd didn't work. Classpath will do the trick better.

* * * * * sudo flock -n /run/lock/cron.lock java -classpath /your/jar/location -jar yourFile.jar

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