How To Set Up A Cron Job In Unraid


Go to solution Solved by tjb_altf4,

Recommended Posts

I have found some older guides for setting up cron jobs in Unraid but none of them seem to work. One guide said put a file in the /etc/cron.d directory. One guide said put a file in /boot/config/plugins directory. Even adding it to the non-persistent crontab -e doesn't do anything. When I issue the update_cron command I see nothing happening in the syslogs. Any direction is appreciated. My file consist of the following:

53 20 * * * * ./mnt/cache/appdata/python/photosync_vid_docker.sh

 

All this does is kick off a python script via docker that moves some files. That script has been tested and works. 

Edited by jneely911
type
Link to comment
  • 7 months later...
On 10/11/2022 at 6:59 AM, jneely911 said:

Thanks tjb_altf4, I did see that as an option. I have some experience with Linux and was hoping just to use cron. I installed user scripts yesterday. I will check it out this afternoon. Thanks

this is kind of old but you can edit cron on /etc/cron.d/root use nano or vi and you can enter what you want but i second user scripts you set it and it enters the cron schedule directly into the file i just mentioned

Link to comment
53 minutes ago, Can0n said:

this is kind of old but you can edit cron on /etc/cron.d/root use nano or vi and you can enter what you want

Actually this will not work as expected as any such edit will not survive a reboot since that location is only in RAM and also Unraid may wipe out the edit at any time.   Using User Scripts plugin takes care of this persistence issue.

 

Link to comment
28 minutes ago, itimpi said:

Actually this will not work as expected as any such edit will not survive a reboot since that location is only in RAM and also Unraid may wipe out the edit at any time.   Using User Scripts plugin takes care of this persistence issue.

 

 

It does work

 

Any changes made to the operating system get written back to the USB immediately.

 

Case in point I came across this post due to an rsync error I was seeing in my logs. I checked user scripts it wasn't there so i found the Rsync command I used to run on a server that doesn't exist anymore in the logs.  I found it in /etc/cron.d in a file called root

 

that server destination has been decommissioned for over a year

 

My newest user scripts from less than a month ago were there too and my server has was restarted just 8 days ago

 

Link to comment

No, it doesn't get saved for me. I have a similar issue and I have no idea where I added that cron job, and no matter how I modify the /etc/cron.d/root file, it always revert back after I restart the server or start the array. I took some instructions on this forum very long ago as there was no such thing as user scripts back then and have no idea how to reset/remove it now

Link to comment
On 6/7/2023 at 8:21 PM, CyberMew said:

No, it doesn't get saved for me. I have a similar issue and I have no idea where I added that cron job, and no matter how I modify the /etc/cron.d/root file, it always revert back after I restart the server or start the array. I took some instructions on this forum very long ago as there was no such thing as user scripts back then and have no idea how to reset/remove it now


it saves for me so not sure what voodoo magic my server is doing but i got some old Cron jobs there before I was using before User scripts came out and i even commented it out due to it not longer being valid and ocassionaly showing the invalid path in my logs when it ran. but after a massive issue last night with BTRFS errors flooding my logs and causing my VM and dockers to all crash I had to reboot forcibly due to stopping array failing and the comment # is still there so not sure what is happening to keep mine there

User Scripts even puts its schedules in there

Link to comment
  • 4 weeks later...

It's coming from your /boot volume (the flash drive) - probably easiest to determine a keyword in your cronjob - something somewhat unique if possible. Then you can do something like this to figure out where that root cron is coming from:

$ grep -r "mykeyword" /boot/

That should give you a list of the possible matches and hopefully it's easy to determine where the root cron is coming from.

Link to comment
51 minutes ago, Delarius said:

It's coming from your /boot volume (the flash drive) - probably easiest to determine a keyword in your cronjob - something somewhat unique if possible. Then you can do something like this to figure out where that root cron is coming from:

$ grep -r "mykeyword" /boot/

That should give you a list of the possible matches and hopefully it's easy to determine where the root cron is coming from.

sadly putting the old server name in the keywords only pulls old syslog files i might have to stop and start the array again to get it to show up in /etc/cron.d/root againi have a sneaking suspecision its an old user.script plugin file lingering and staying active but could be something else

Link to comment

It's definitely somewhere on that /boot drive, just a matter of figuring out how to search for it. Not sure using the old servername is the right approach. The cronjob will no doubt look something like this:

5 4 * * 0 /root/backup.sh

 

So in this instance I'd try using "backup.sh" as my keyword.

Link to comment
15 minutes ago, Delarius said:

It's definitely somewhere on that /boot drive, just a matter of figuring out how to search for it. Not sure using the old servername is the right approach. The cronjob will no doubt look something like this:

5 4 * * 0 /root/backup.sh

 

So in this instance I'd try using "backup.sh" as my keyword.

yeah i will make a better note when it comes back after a stop and start of the array

no luck finding it so far

 

Link to comment
4 hours ago, Delarius said:

It's definitely somewhere on that /boot drive, just a matter of figuring out how to search for it. Not sure using the old servername is the right approach. The cronjob will no doubt look something like this:

5 4 * * 0 /root/backup.sh

 

So in this instance I'd try using "backup.sh" as my keyword.

So just noticed it showed up again with no stop n start of the array

here is a screnshot of the the /etc/cron.d/root file

and maybe i using grep wrong but no results using the cron schedule with rsync command and its options (Attached too)
 

persistent cron.png

no results.png

Link to comment
12 hours ago, Delarius said:

It's definitely somewhere on that /boot drive, just a matter of figuring out how to search for it. Not sure using the old servername is the right approach. The cronjob will no doubt look something like this:

5 4 * * 0 /root/backup.sh

 

So in this instance I'd try using "backup.sh" as my keyword.



found it!! thank you for your help

root@Thor:~# nano /etc/cron.d/root
grep -r "Backup Share to Freya" /boot/
/boot/config/plugins/dynamix/thor2freya.cron:#*** rsync Thor's Backup Share to Freya

Link to comment
24 minutes ago, Can0n said:



found it!! thank you for your help

root@Thor:~# nano /etc/cron.d/root
grep -r "Backup Share to Freya" /boot/
/boot/config/plugins/dynamix/thor2freya.cron:#*** rsync Thor's Backup Share to Freya

Thanks so much for sharing your findings! Mine was placed there as well. I think this was the post I came across last time

 Finally, I can resolve it now. 

  • Like 1
Link to comment
7 hours ago, itimpi said:

I would suggest searching the boot drive as indicated using 'Freya_Backup' as the search string as that looks unlikely to give many false positives.



found it under /boot/config/plugins/dynamix/thor2freya.cron

renamed it thor2freya.cron.old

I have other crons I created there I am going to remove


I created that almost 5 years ago when i had 3 unraid servers. the Freya ultimately died and i recycled it

the 3rd one has become a windows Server 2022 Printer Server as the case drive bays was killing drives at an alarming rate. now its just a single 256GB SSD laying inside the case

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.