Adding cron jobs to the UDM Pro ( Dream Machine Pro )
The UDM Pro isn’t so “pro” since there are some essential features missing from the UI interface (eg: SNAT / DNAT ) nonetheless we can “hack” our way into getting what we want -ish.
There is a fantastic project/effort on GitHub to allow users to run scripts on the boot of the UDM Pro, we will use this to our advantage!
unifi-utilities/unifios-utilities
We are particularly interested in the on-boot-script
On this page
Installing on-boot-script on the UDM-Pro
First, we need on-boot-script installed on the UDM, check out how to do this in my guide over here
SSH access to the UDM
there are two ways to get SSH access, enabling it and SSH’ing into the box, or using the debug option from the Unifi manage interface
SSH’ing using the debug interface
head over to your Unifi network interface and go to “unifi devices”
Locate your UDM and click on it, go to settings and in the bottom open the “Manage” tab and click on debug
this will open a live SSH session to your UDM
SSH using a direct connection
you can directly SSH into the UDM with the credentials configured under “Console Settings”
Adding the cron job boot script
NOTE: 04/2023: the location has changed from /mnt/data to /data, so screenshots are out of date
Let’s grab the cron script from the repo and add it to the on_boot.d folder
cd /data/on_boot.d/ curl https://raw.githubusercontent.com/unifi-utilities/unifios-utilities/main/on-boot-script/examples/udm-files/on_boot.d/25-add-cron-jobs.sh --output 25-add-cron-jobs.sh chmod +x 25-add-cron-jobs.sh
With this script being present, on boot, it will copy cronjobs from
/data/cronjobs/ ➡️ to ➡️ /etc/cron.d/
If you want a cron job, make sure to add it to /mnt/data/cronjobs/ (be sure to add the folder first)
mkdir /data/cronjobs/
Example of my UptimeRobot cron job (guide here):
cat /data/cronjobs/uptimerobot * * * * * root curl -fsL "https://heartbeat.uptimerobot.com/xxx" >/dev/null 2>&1