Adding sort-of cron jobs to Synology DSM 5

I wanted to write a cron job to run a php script, so I found a way to regularly call a php script.

Go to the Control Panel, and click on “Task Scheduler” under “System”. Select “Create” –> “User-defined script”.

Under “User-defined script”, type in the following…

curl "http://example.com/cron.php"

…replacing

"http://example.com/cron.php"

with whatever script you run. I’ve found it seems to work well with regular cron jobs like a Dynamic DNS (DDNS) update.

UPDATE: See Simon’s comment below for more information on scheduling tasks!

Advertisements

9 thoughts on “Adding sort-of cron jobs to Synology DSM 5”

  1. Many thanks for your explanation. I had missed this section of DSM and was editing the crontab directly to perform the same task. This gui is much less hassle.

    It may be worth knowing two things about these scheduled tasks:

    1) That the actual driver of these tasks is cron itself. Each task gets entered into the crontab as follows:-

    0 1 * * * root /tmp/synoschedtask –run id=1

    Each time you add a new task a new line goes into the crontab and the id number in the new task increases by one.

    2) All tasks will execute as the root user. However the execution environment is not quite the same as the shell path when logged in as root.

    This means that scripts that run just fine from the command prompt may not run well as a scheduled task.

    For instance if your script drives “java” you will have to insert the full path to “java” in order for it to execute within the scheduled script.

    A failure to find a command due to a missing path will result in a silent failure. Followed by much scratching of your head whilst you figure out what went wrong.

    If your script doesn’t work first time, appending

    2>&1 >> /volume1/public/logfile.txt

    to the end of each line should trap most of your errors to the logfile and let you correct them. Even then it didn’t catch the missing path error for “java”, which was truly a silent failure.

  2. Hi i was wondering if you could help.When I run a script in Task Scheduler. it is running the file I want but the output is going to the root instead of the folder the file is ran in like it should. Would you be able to shed some light how I can stop this happening?

    Thanks

    1. It depends a little on what process you are running, but you can change the script you are running to either:
      – tell the process to write the output of the process to a file. Like curl for instance (and some programs tend to do this), you would say “curl http://google.com -o /path/to/file.txt”, or
      – redirect the output of the process using the “>” operator. Like for instance, “ls > files.txt”.

      Hope that helps 🙂

      1. Hi Anthony,

        What I am doing is using a programme called mc2xml to generate a xmltv file for my EPG. I copy the file over to one of my shared folders on the NAS. Before I set up a cron job or use the task scheduler I decided to test with Terminal on my Mac first. When I run mc2xml on my Mac it produces 2 files in the directory I run it from.
        The command I am using is:
        /volume1/Nas_share/mc2xml -c gb -g “My postcode”
        It generates the the files correctly but they end up in the root, where I can’t access from Openlec and can’t make it NFS because they are not in a actual folder. I’m probably missing something here as I am fairly new to using Terminal.
        Any help would be great.

        Thanks.

      2. So I looked up mc2xml.hosterbox.net and it looks like adding “-o /path/to/output/file” should work, in addition to your other parameters…

  3. You can ignore the -c and -g commands, they are just to select the right region for the TV guide.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s