2

We have tens of Ubiquiti Edgerouter-X's on active on customer locations. They among other things responsible for pinging an IP each minute. This is done by a cronjob (set with crontab -e) and works fine as long as the firmware is not updated.

When the firmware is updated to a newer version, the cronjobs are "reset" to the default value. After some research i noticed that i should use the system task-scheduler instead of a cronjob. So i created an ping.sh file in /config/scripts/, set the permissions to 0755 and did an chmod +x ping.sh. This is the content of the ping.sh file (for test purposes)

#!/bin/bash
echo "Ping Pong!"
echo "Ping Pong!!" >> result.txt    

When i execute the script manually ./ping.sh the script works fine, it echo's Ping Pong! and writes Ping Pong!! to result.txt. When i try to execute the script with the system task-scheduler it does nothing. I tried 2 task scheduler configurations and restarted the Edgerouter after commit; save;:

show system task-scheduler task
 task ping-task {
     crontab-spec "* *  *   *   *"
     executable {
         path /config/scripts/ping.sh
     }
 }

and

show system task-scheduler task
 task ping-task {
     executable {
         path /config/scripts/ping.sh
     }
     interval 1m
 }

What do i wrong? I checked multiple topics about it on https://community.ui.com/ but could not find a solution...

CodeNinja
  • 143

1 Answers1

6

Your solution seemed perfectly fine to me (running on a EdgeRouter X v2.0.9-hotfix.1).

I believe you just had some problem with relative paths or permissions when writing your result.txt file.

I did set an absolute path for result.txt (in /tmp directory) and it worked for me:

cat > /config/scripts/pinger.sh <<'EOF'
#!/bin/bash
echo "Ping Pong!!" >> /tmp/result.txt
EOF

chmod +x /config/scripts/pinger.sh

configure set system task-scheduler task pinger executable path /config/scripts/pinger.sh set system task-scheduler task pinger interval 1m commit ; save ; exit

watch cat /tmp/result.txt

With the last command you can see a line being added every 1 minute.