0

Ubuntu 18.04

I'd like to check, when a user logs in, that his share point(s) is/are mounted. If not, it prompts the user if he wants to mount it. If yes the mount command is executed, which will prompt the user for it's password.

Works ok but a Failed to query password: Permission denied error message appears, which is not the case when the script is run by it's self.

How can I suppress that?

Last login: Fri Jan 25 10:59:55 2019 from xxx
Your NAS volume "/data/lambda/nas" is not mounted.
Do you want to mount it (y/n)? y
Failed to query password: Permission denied
Password for lambda@//10.40.40.13/s-dept/lambda:

Here's my script

# shellcheck shell=sh

exec 3<&0
grep $USER /etc/fstab | cut -f 2 | while read -r  line ; do
        if ! grep -qs $line /proc/mounts; then
                echo "Your NAS volume \"$line\" is not mounted."
                read -u 3 -p 'Do you want to mount it (y/n)? ' -n 1 -r
                echo
                if [[ $REPLY =~ ^[Yy]$ ]]
                then
                        mount $line
                fi
        fi
done
exec 3<&-

Edit: As requested, here's a /etc/fstab line

//10.40.40.13/s-dept/lambda /data/lambda/nas    cifs    noauto,users,username=lambda    0   0
  • 3
    Perhaps you need to show the relevant lines from your /etc/fstab – wurtel Jan 25 at 10:41
  • @wurtel, I've added the requested line. – kaklon Jan 25 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.