DSM 6.1-15047 Update 1
There's bug/defect in task scheduler in that a user-defined script scheduled to run as a non-root user is executed in an environment where $USER is root, $HOME is /root, and the starting directory is /root, which shouldn't be readable by non-root users. This leads to permission errors when executing standard utilities like find(1).
Expected behavior: $USER is set to the user the script is scheduled to run as; $HOME and the starting directory are set to the home directory of $USER.
By the way, I know how to work around the issue. I'm reporting this to hopefully have this behavior fixed, rather than asking for a workaround.
Create the following script:
#!/bin/sh
echo -n "pwd: "
pwd
echo "USER: $USER"
echo "HOME: $HOME"
find /volume1
(The support form doesn't really support <pre>
blocks; in case formatting is messed up, here's the script hosted on GitHub: https://gist.githubusercontent.com/anonymous/edb2df691b3df377d9e49554a78176db/raw/a7c074b03376c3b750a183112e5f06773a6d8fb2/synology-task-scheduler-script.)
Now, create a user-defined script in Task Scheduler, with user set to a non-root user, and put the path to the script above in the "Run command" section of "Task Settings". Enable email notification so that we can see the output.
Result:
Standard output/error:
pwd: /root
USER: root
HOME: /root
find: cannot get current directory: Permission denied
If you prepend your script with
where user means the user under which account the task is scheduled (e.g. admin)
It seems to work at least for the tastk had problems with.