When this script was run from crontab I was getting the error below. It was happening, because su does not initialize the environment variables for the user (in this case $HOME).
Switching to su - solved the problem for me.
could not change directory to "/root": Permission denied
could not change directory to "/root": Permission denied
could not change directory to "/root": Permission denied
could not change directory to "/root": Permission denied
could not change directory to "/root": Permission denied
could not change directory to "/root": Permission denied
When this script was run from crontab I was getting the error below. It was happening, because
su
does not initialize the environment variables for the user (in this case $HOME). Switching tosu -
solved the problem for me.