unifi-utilities / unifios-utilities

A collection of enhancements for UnifiOS based devices

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cron.d jobs not working despite correct syntax

borez opened this issue · comments

commented

Describe the bug
My cron.d scripts don't seem to work after migrating to 2.x. Am now running 3.0.20 and didn't realise the crontab wasn't running.

Created a weekly cron script to copy Unifi Network backup databases to the 3.5" HDD. This was the same script used for 1.x firmware, which worked with no issue.

25-add-cron-jobs.sh is updated to the latest version and runs without any issue (the /data/cronjobs files gets copied to /etc/cron.d). However, running crontab -l shows no crontab for root.

I realise most of Unifi's own cron scripts have a "root" appended in front. However, adding the "root" user didn't help either.

0 22 * * 1 cp -r /data/unifi/data/backup/autobackup/. /volume1/share/backup/UDMBackup/

try this
0 22 * * 1 root /bin/cp -r /data/unifi/data/backup/autobackup/. /volume1/share/backup/UDMBackup/

commented

try this 0 22 * * 1 root /bin/cp -r /data/unifi/data/backup/autobackup/. /volume1/share/backup/UDMBackup/

Thanks for this but this didn't work either.

Had the same problem. Adding "root /bin/" before the cron command solved it for me.

commented

Had the same problem. Adding "root /bin/" before the cron command solved it for me.

Thanks, I couldn't get it to work. Do you mean by:

root /bin/ 0 22 * * 1 cp -r /data/unifi/data/backup/autobackup/. /volume1/share/backup/UDMBackup/

@borez, below is the example of my files:


/data/on_boot.d/25-add-cron-jobs.sh

#!/bin/bash
# Get DataDir location
DATA_DIR="/data"
case "$(ubnt-device-info firmware || true)" in
1*)
    DATA_DIR="/mnt/data"
    ;;
2*)
    DATA_DIR="/data"
    ;;
3*)
    DATA_DIR="/data"
    ;;
*)
    echo "ERROR: No persistent storage found." 1>&2
    exit 1
    ;;
esac
## Store crontab files in ${DATA_DIR}/cronjobs/ (you will need to create this folder).
## This script will re-add them on startup.

cp ${DATA_DIR}/cronjobs/* /etc/cron.d/
/etc/init.d/cron restart

exit 0

/data/cronjobs/ula-config

* * * * * root /bin/sh /data/ula/ula-config.sh
commented

@GentleHoneyLover

Thanks for this. I've tried multiple versions, but it still doesn't work. My /data/on_boot.d/25-add-cron-jobs.sh file is the same as yours.

Configuration in /data/cronjobs/backup

0 20 * * * root /bin/sh /data/backup.sh

Configuration in /data/backup.sh, 0755 permissions with chmod +x done. Running this file has no issues.

#!/bin/bash

cp /data/unifi/data/backup/autobackup/* /volume1/share/backup/UDMBackup/

Also, checking /var/log/cron.log also shows no activity of crontab loading.

@borez, can you double-check the corn restart command in /data/on_boot.d/25-add-cron-jobs.sh (third line from the bottom)? In my case I had to change it from whatever it was in the template to /etc/init.d/cron restart

commented

Thanks again for helping. I had factory reset my UDM PRO, and reinstalled the scripts. Apologies for the wrong mention earlier.

#!/bin/bash
# Get DataDir location
DATA_DIR="/data"
case "$(ubnt-device-info firmware || true)" in
1*)
   DATA_DIR="/mnt/data"
   ;;
2*)
   DATA_DIR="/data"
   ;;
3*)
   DATA_DIR="/data"
   ;;
*)
   echo "ERROR: No persistent storage found." 1>&2
   exit 1
   ;;
esac
## Store crontab files in ${DATA_DIR}/cronjobs/ (you will need to create this folder).
## This script will re-add them on startup.

cp ${DATA_DIR}/cronjobs/* /etc/cron.d/
# Older UDM's had crond, so lets check if its here if so use that one, otherwise use cron
if [ -x /etc/init.d/crond ]; then
 /etc/init.d/crond restart
elif [ -x /etc/init.d/cron ]; then
 /etc/init.d/cron restart
else
 echo "Neither crond nor cron found."
fi

exit 0

Running the script showed

Restarting cron (via systemctl): cron.service.

hi all, very helpful post! I also see No crontab for root, even though I manually copied cron files into /etc/cron.d . This is a new installation and I can't for the life of me find how to see pending cron jobs in that folder since they are systemwide, not user based. My cronjob is fairly simple(and no . characters in cron filename):
`0 23 * * * root /usr/bin/ssh username@x.x.x.x "swctrl poe set off id 5 ; swctrl poe set off id 1 ; swctrl poe set off id 4"

///edit: cron jobs working as expected. No issue thus far and working great for shutting down APs at nighttime.
`