Cron job doesn't execute Topic is solved

Having issues with your DietPi installation, or, found a bug? Post it here.
Seferi
Posts: 16
Joined: Mon Sep 23, 2019 4:07 pm

Cron job doesn't execute

Post by Seferi »

Hi,

there is a jar file I have to execute everyday at 10:00 AM. I added the below options with crontab -e but it fails to execute. I appreciate if someone could help. Thanks in advance..

0 10 * * * java --add-opens java.base/java.lang=ALL-UNNAMED -jar /home/user/folder/folder/Reminder.jar

0 10 * * * root (cd /home/user/folder/folder/; java --add-opens java.base/java.lang=ALL-UNNAMED -jar Reminder.jar)
User avatar
Joulinar
Posts: 2662
Joined: Sat Nov 16, 2019 12:49 am

Re: Cron job doesn't execute

Post by Joulinar »

Hi,

did you tried to put your command into a script and have this executed from there?
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Seferi
Posts: 16
Joined: Mon Sep 23, 2019 4:07 pm

Re: Cron job doesn't execute

Post by Seferi »

Thanks for the reply mate. I didnt try yet. As described here:
https://unix.stackexchange.com/question ... e-in-linux
???
User avatar
trendy
Posts: 161
Joined: Tue Feb 25, 2020 2:54 pm

Re: Cron job doesn't execute

Post by trendy »

Crontab -e will edit the cron for the user who is running the command, for example dietpi or root.
Better use the full path to the java command, otherwise it might fail for that.
Also the second command is supposed to run as root? Then you need to add it in root's crontab.
Seferi
Posts: 16
Joined: Mon Sep 23, 2019 4:07 pm

Re: Cron job doesn't execute

Post by Seferi »

Seferi wrote: Thu Oct 08, 2020 1:20 pm Hi,

there is a jar file I have to execute everyday at 10:00 AM. I added the below options with crontab -e but it fails to execute. I appreciate if someone could help. Thanks in advance..

0 10 * * * java --add-opens java.base/java.lang=ALL-UNNAMED -jar /home/user/folder/folder/Reminder.jar

0 10 * * * root (cd /home/user/folder/folder/; java --add-opens java.base/java.lang=ALL-UNNAMED -jar Reminder.jar)
One of those two just got executed (don't know which one) at a completely wrong time.. Does cron use a different time then the system time ?
User avatar
Joulinar
Posts: 2662
Joined: Sat Nov 16, 2019 12:49 am

Re: Cron job doesn't execute

Post by Joulinar »

Cron job uses the server's define timezone if I'm not mistaken. To find the timezone

readlink -f /etc/localtime
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Seferi
Posts: 16
Joined: Mon Sep 23, 2019 4:07 pm

Re: Cron job doesn't execute

Post by Seferi »

Strange.. According to output from this: readlink -f /etc/localtime
The time zone is correct...
User avatar
Joulinar
Posts: 2662
Joined: Sat Nov 16, 2019 12:49 am

Re: Cron job doesn't execute

Post by Joulinar »

you could check what happen on cron and what time thinks got executed

Code: Select all

journalctl -u cron.service
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Seferi
Posts: 16
Joined: Mon Sep 23, 2019 4:07 pm

Re: Cron job doesn't execute

Post by Seferi »

Joulinar wrote: Thu Oct 08, 2020 7:19 pm you could check what happen on cron and what time thinks got executed

Code: Select all

journalctl -u cron.service
Very strange.. Journal said it executed in the right time.. But it didn't do anything. I tried rebooting and it suddenly started working. So everytime I add a cronjob it doesn't take effect until I reboot but strangely before reboot, journal says the code was executed...
User avatar
Joulinar
Posts: 2662
Joined: Sat Nov 16, 2019 12:49 am

Re: Cron job doesn't execute

Post by Joulinar »

Probably it's enough to restart cron.service to get it activated. But strange that this would be needed. :?
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Post Reply