Cron – Mounting fuse sshfs fails when invoked by Cron on FreeBSD 9.0

cronfreebsdfusesshfs

I have a remote server filesystem that I'm attempting to mount locally on a FreeBSD 9 machine via FUSE sshfs, and Cron for a backup routine. I have ssh keys between the boxes setup to allow for passwordless login as the root user on the local machine.

Cron is set to run the following script (in Root's crontab):

#!/bin/sh

echo "Mounting Share"

/usr/local/bin/sshfs -C -o reconnect -o idmap=user -o workaround=all <remote user>@<remote domain>.com: /mnt/remote_server

As root, I can run this script on the command line without issue, and without being asked for a password the share mounts successfully. Yet, when run by Cron the script fails. The path to sshfs is identical to the value of which sshfs

Here is the email root receives from the Cron Daemon:

X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>

Mounting Share
fuse: failed to exec mount program: No such file or directory
fuse: failed to mount file system: No such file or directory

I'm stumped as to why I'm receiving No such file or directory in this instance. It further seems odd given that the paths appear to be correct.

I've also attempted to compare the output of env on the shell with env inserted into the script. I don't see any environment variables that should cause this trouble. At bootup, FUSE reports its version as:

fuse4bsd: version 0.3.9-pre1, FUSE ABI 7.8

Help me ServerFault wizards, you're my only hope!

Best Answer

It turns out the $PATH environment variable was the cause of this issue. Modified the script above set the PATH identically to the shell, and now it works without issue:

 PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/‌​root/bin"   
 export PATH 

I guess the lesson is never to make any assumptions about the minimal Cron environment.