"pun_pre_hook_root_cmd" execution error

I’m using OOD 3.1.1 and trying to configure the creation of a home directory when a user logs in.
For this purposes I use a parameter in ood_portal.yml
pun_pre_hook_root_cmd: ‘/pun_pre_hook’
The “pun_pre_hook” script is very simple

## script accepts a string "--user USERNAME" from OOD
## so USERNAME is the second parameter - $2

# check if user's home directory exist, if not create it
if [ ! -d /home/$2 ]; then
 mkdir /home/$2
 chown -R $2:$2 /home/$2

But when a user without a home directory logs in, every time an error occurs “Permission denied @ dir_s_mkdir - /home/test”
I don’t understand why this is happening. The documentation says that “pun_pre_hook_root_cmd” runs with root rights.

I am attaching a ondemand-nginx error.log file
error.txt (5.1 KB)

Please help me solve the problem.

Are you sure the script is being executed? You can use the logger command to send messages to the syslog or you can redirect output to a temporary file to see what’s happening in the script.

Thanks for advice.
I changed the pun_pre_hook_root_cmd to
pun_pre_hook_root_cmd: ‘/pun_pre_hook 1>/log 2>/log-error’

So after login (again with an error) there are no log files in /
It seems that script is not executed at all.
That’s another question why it is not running? How to fix it?

Just in case, I checked that the script runs directly from cmd without errors.

There could be an apache log line that has some info in it.