2

Ok, this is hard to distill to a single question because it really depends on how I'm going to troubleshoot it.

The following script is meant to pipe mount.cifs commands to a while loop that enters password for three password prompts. The commented out blocks are attempts to debug the fact that it isn't responding to the prompt.

#!/bin/bash

printf "How many atoms are there in the universe?\nAnswer:"
read -s $pwd
echo -e "\nThanks.\n"
while read prompt ; do
#     printf "prompt = $prompt" > /dev/stdout
#     ${prompt//"\n"/"\\n"}
#     printf "prompt is" >foo
    if [ "$prompt" = "Password: " ]; then
    echo -e "$pwd\r\n" > /dev/stdin
    fi
done < <(
    sudo mount.cifs "//192.168.1.2/My Music" /home/pi/Desktop/Music -o     user=Rob_
    sudo mount.cifs "//192.168.1.2/My Videos" /home/pi/Desktop/Videos -o     user=Rob_
    sudo mount.cifs "//192.168.1.2/My Pictures" /home/pi/Desktop    /Pictures -o user=Rob_
)

The 'prompt' variable does not seem to meet the condition, but the debug printouts are being swallowed up even after manually redirecting to /dev/stdout?

If someone could at the very least tell me how I can print debug info in this scenario I would be grateful, and if they want to tell me how to solve this problem outright (preferably by the method I was shooting for, but if you have a more elegant one I'd be interested to see it) then I'd appreciate that, too.

EDIT: For the record I'm aware that you can supply the password directly to the command, I'm just doing this as a test for myself.

2 Answers 2

1

I've since tried tackling the problem from a different angle, using the 'expect ' command. However the following fails to work:

#!/usr/bin/expect
spawn sudo mount.cifs "//192.168.1.2/My Pictures" /home/pi/Desktop/Pictures -o user=Rob_
expect "Password: " {
    set send_slow {1 .1}
    send -s "a_password"
}

It responds to the password prompt by typing it in, but fails to mount the drive, so I'm not sure where the input is going to. I can supply any old garbage with 'send' and it happily closes without an error message, whereas if I enter the command from the shell it either protests that the password is wrong or mounts successfully.

I'll upload this as a separate question if noone answers here.

-1

There are multiple reasons:

  • Your debug printf didn't work, because mount prints its prompt to the terminal, not stdout. read prompt failed and the loop was never entered.

  • You are trying to echo the password to /dev/stdin. This will not work, you can only read from it.

  • the mount's stdin is still connected to the terminal. There is no way to emulate user typing in terminal

  • Even if you make mount's stdin be a pipe, for security reasons mount will still detect the terminal and read from it, not pipe

What you actually need is a password file. Read man mount.cifs:

credentials=filename

You can try to supply a fake password file using bash command substitutuon:

credentials=<( echo "password=$pwd" )
5
  • As far as I can see a password file is itself a security liability. I want it so that an actual human has to type in the password (and only once, despite there being three prompts)
    – Rob F
    Commented Jul 2, 2015 at 22:46
  • @RobF You can try to supply a fake password file
    – basin
    Commented Jul 3, 2015 at 6:20
  • The original question was mainly about why the debug printf's that were commented out weren't showing in the console. As to the password file; it seems a password supplied through PASSWD_FILE (with the proper formatting, I didn't make that mistake), PASSWD, the password= parameter in the options; all get ignored and I get prompted for the password anyway!? I can also enter any garbage as the credentials file and it won't show an error.I might want to look into this as a separate problem if you don't know the answer...
    – Rob F
    Commented Jul 3, 2015 at 7:22
  • @RobF Your debug printf didn't work, because mount prints its prompt to the terminal, not stdout
    – basin
    Commented Jul 3, 2015 at 7:53
  • read prompt failed and the loop was never entered
    – basin
    Commented Jul 3, 2015 at 7:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .