I am able to mount a remote SFTP directory using the root user, however when I try to run a bash script to automate the same, the script runs with no errors, however the mount is never created.
I'm using:
#!/bin/bash
_SSHHOST="sub.domain.com"
_SSHUSER="10001"
_SSHPASS="somepass"
_DATADIR="/mnt/data"
# Create user if doesn't exist
id -u $_SSHUSER &>/dev/null || useradd $_SSHUSER
# Create directory if doesn't exist
mkdir -p $_DATADIR/$_SSHUSER
# Change ownership of dir to new user
chown $_SSHUSER:root $_DATADIR/$_SSHUSER
/usr/bin/expect <<EOD
spawn sshfs $_SSHUSER@$_SSHHOST:/remote/dir $_DATADIR/$_SSHUSER
expect "Password: "
send "$_SSHPASS\r"
expect "#"
EOD
No mount is created and there are no files listed in the created directory. I appreciate that some people will say to avoid using Bash and create this directly in Expect, however this is just a very small portion of a larger script that performs numerous bash functions. What am I doing incorrectly?
Thanks for your help.
UPDATE
I fixed this by passing -o password_stdin
into the sshfs
command. Thanks everyone for looking.