Jump to content

User Scripts Custom Cron Schedule not working


Go to solution Solved by Daburgers,

Recommended Posts

Posted (edited)

Hi All,

I am having an issue where my user scripts will not work/run ONLY when using a custom cron schedule. I only have 3 scripts. An antivirus script, clear drive script and a simple script to power down the server. 

 

I first tried setting a custom cron schedule for the antivirus script, but nothing would happen. However, the script runs fine in the foreground, background, and by using the pre-defined schedule options (ie. at stopping of array, schedule hourly etc).


So I made a new simple script to power down the server and it too would do nothing when I had a custom cron schedule set. The script to power down the server contains the following:


#!/bin/bash
powerdown

 

I set the custom cron schedule to:

0 9 * * *
(9am every every day - I did try different times as well....9:05am, 11:30am - 5 9 * * * , 30 11 * * * , etc)

Nothing happens and no log recorded. To state the obvious, I made sure to set it at a time a well ahead of the current time, no joy!

However, when I click 'run script', 'run in background', or using the pre-defined schedule (I used 'at stopping of array' for testing), the script ran each time without an issue and the device powered down accordingly. A log was created as well.

I have attached the unraid logs in case that helps. Appreciate any assistance that anyone can offer!

When reading through the forums on this kind of issue, someone with a somewhat similar issue was advised to run a couple of commands which may help find out what's going on, although I am not sure what to look for. I thought I'd include them in case it helps as well. Please see below:

root@Tower:~# crontab -l
# If you don't want the output of a cron job mailed to you, you have to direct
# any output to /dev/null.  We'll do this here since these jobs should run
# properly on a newly installed system.  If a script fails, run-parts will
# mail a notice to root.
#
# Run the hourly, daily, weekly, and monthly cron jobs.
# Jobs that need different timing may be entered into the crontab as before,
# but most really don't need greater granularity than this.  If the exact
# times of the hourly, daily, weekly, and monthly cron jobs do not suit your
# needs, feel free to adjust them.
#
# Run hourly cron jobs at 47 minutes after the hour:
47 * * * * /usr/bin/run-parts /etc/cron.hourly 1> /dev/null
#
# Run daily cron jobs at 4:40 every day:
40 4 * * * /usr/bin/run-parts /etc/cron.daily 1> /dev/null
#
# Run weekly cron jobs at 4:30 on the first day of the week:
30 4 * * 0 /usr/bin/run-parts /etc/cron.weekly 1> /dev/null
#
# Run monthly cron jobs at 4:20 on the first day of the month:
20 4 1 * * /usr/bin/run-parts /etc/cron.monthly 1> /dev/null
8 9 * * * /usr/local/emhttp/plugins/nvidia-driver/include/update-check.sh &>/dev/null 2>&1
# Job for VM Backup plugin default:
0 3 * * 0 /usr/local/emhttp/plugins/vmbackup/runscript.php run_backup default > /dev/null 2>&1

 

 

root@Tower:~# cat /etc/cron.d/root
# Generated docker monitoring schedule:
10 0 * * 1 /usr/local/emhttp/plugins/dynamix.docker.manager/scripts/dockerupdate check &> /dev/null

# Generated system monitoring schedule:
*/1 * * * * /usr/local/emhttp/plugins/dynamix/scripts/monitor &> /dev/null

# Generated mover schedule:
0 0 1 * * /usr/local/sbin/mover &> /dev/null

# Generated plugins version check schedule:
10 0 * * 1 /usr/local/emhttp/plugins/dynamix.plugin.manager/scripts/plugincheck &> /dev/null

# Generated array status check schedule:
20 0 * * * /usr/local/emhttp/plugins/dynamix/scripts/statuscheck &> /dev/null

# Generated Unraid OS update check schedule:
11 0 1 * * /usr/local/emhttp/plugins/dynamix.plugin.manager/scripts/unraidcheck &> /dev/null

# Generated cron settings for docker autoupdates
0 0 * * * /usr/local/emhttp/plugins/ca.update.applications/scripts/updateDocker.php >/dev/null 2>&1
# Generated cron settings for plugin autoupdates
0 0 * * * /usr/local/emhttp/plugins/ca.update.applications/scripts/updateApplications.php >/dev/null 2>&1

# CRON for CA background scanning of applications
57 * * * * php /usr/local/emhttp/plugins/community.applications/scripts/notices.php > /dev/null 2>&1

# Generated system data collection schedule:
*/1 * * * * /usr/local/emhttp/plugins/dynamix.system.stats/scripts/sa1 1 1 &> /dev/null

# Generated cron schedule for user.scripts
0 9 * * * /usr/local/emhttp/plugins/user.scripts/startCustom.php /boot/config/plugins/user.scripts/scripts/powerdown/script > /dev/null 2>&1

 

image.thumb.png.9b8f7a18cc113de4ba19e0123f103e77.png

tower-diagnostics-20240909-0934.zip

Edited by Daburgers
provided more clarity and context
Posted

I probably should have posted this in that thread tbh! Thanks for sharing.

I did find a fair few people with the same issue. Most didn't have provide an update as to if it worked or not.
I assume they either forgot about it or gave up. 

This image below I also ran the same command I added in my first post. I can see the last line shows my cron line added.
"until it runs you won't see anything". Not sure if this person had a different issue or the same issue but not explained properly.
For me, I set the time to 9:00am. It would have been 8:45am at the time of setting the schedule up. At 9am, nothing happens.
image.thumb.png.96100dda92d12f085133ec09619bf484.png

This one seems to be just a question. I assume they were having a similar issue as me but didn't go into detail or also forgot. Not sure:
image.thumb.png.50fa54cfe0b3e8aa137a0b9750f5a159.png

This is exactly thew issue I am having. I have it set exactly as this, but does not work. Unfortunately, I wasn't able to see if they managed to get it to work:
image.thumb.png.c05012e49b6c9770aa3e5a957e68663c.png

Nevertheless, I will submit this question in that thread since it is specific to that plugin. Thanks again for sharing the link!

  • Solution
Posted

I managed to resolve the issue. For those who come across with the same issue, the issue was that the system time in unraid was incorrect - even though I had manually set it correctly.

 

What happened was I noticed my server was actually powering down, but not at the right time. So that made me think it has to be my date & time settings. So I checked them again for the 4th time, and this is when I noticed the issue.

 

The Time & Date were manually set, and correctly, but for some strange reason the "New date & time" at the bottom of the settings was not correct.

 

So I decided to use NTP servers to see if that made any difference....and it did! The time adjusted correctly!

I tested out my script again with a new schedule and BOOM - it worked!

 

Attached is an image of my settings before and after I made the changes:

 

image.thumb.png.95b0f8056ab4a44be7cc8a4df3032400.png

  • Like 1

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.

×
×
  • Create New...