I'm writing a backup script which copies a series of directories over to an NFS server using a cron job run from root. The NFS server has the root_squash option defined in its /etc/exports file, so the script is essentially run as nobody, and thus doesn't have the necessary permissions to write where I need it to on the server.
The script comprises mainly of a series of functions which get called at the end to perform the backup (each function is for a different directory). I thought to run the functions as the user who owns the directories on the nfs server would essentially bypass the root_squash option, allowing the functions to run. So, a simple example is:
rsync -av /home/user1 /media/nfsmount/backup
su - user1 -c backup_dir1
Since the script's running from a root cron job, it doesn't ask for the user's password, but it gives this error:
zsh:1: command not found: backup_dir1
(user1's shell as defined in /etc/passwd in this example is /bin/zsh). So it seems when the su - command is initiated, it isn't aware of the functions defined in the script, which makes sense.
Is there a way I can pass the functions from the script to the su command such that it'll know what backup_dir1 is?