bash script with "mount -t cifs" hangs

Dear all,

I have a bash script that mounts a number of samba shares, but one particular mount command makes it hang. Strangely, the same command works when executed directly from the command line:

sudo mount -t cifs //name-of-share /media/FTPpublic -o username=myname

asks for the password and then mounts the share as expected.
In the script, I have the line:

sudo mount -t cifs //name-of-share /media/FTPpublic -o username=$usn,password=$usp

where usn and usp are user name and password entered earlier. This works for all other mount commands in the script, but wherever I put the line with this particular share, it just hangs at this point.

Any help will be greatly appreciated.

Cheers
Stan

Try putting $usn and $usp in "quotes", if they have spaces the shell might be splitting them otherwise.

When in doubt, echo the line to make sure it's ending up as what you think it is.

Any relevant messages in dmesg?

Thanks for the quick reply! There are no spaces in $usn and $passwd and the same format works for the other mount commands in the script.
dmesg records the following error messages, but only after I stop the hanging script by CTRL-C:

[10729.713718] CIFS VFS: Error connecting to socket. Aborting operation
[10729.713743] CIFS VFS: cifs_mount failed w/return code = -512

A quick google search did not reveal anything relevant for this error code, but since it only happens after aborting the script, this is probably not the culprit.

Try quoting them anyway.

Have you tried echoing the line, to make sure it really ended up the way you thought it would?

I was thinking about echoing the line and then pasting it into a terminal window, but then my password would be displayed in clear text and saved in the terminal history. Is there a way to avoid that?

I don't mean echoing it for copy-paste -- there's no good reason a line that works when typed into your shell shouldn't work in a script. I just mean printing the line to see if you notice any glaring errors in it -- perhaps the password contained special characters or something that the script mangled, your variables had unexpected spaces or newlines in them, and so forth.

But running it in the shell would be a decent test too.

How to clear your history file depends on what your shell is, what is it?

[edit] You have bash, so rm ~/.bash_history should delete your history. Beware that this file is only updated AFTER you logout of your shell, so don't delete it in the same session: do the operation, logout, login, then delete it.

It's a unix shell in gnome-terminal.
Suddenly the mount command does not seem to work from the terminal, either. I have a suspicion, but need to check it out. Will report back when done.

There's lots of UNIX and lots of UNIX shells, and what graphical program it's running inside doesn't really matter. You already told me it's BASH, though -- sorry about that, the question's become almost reflexive :o

SOLVED! (sort of)
The problem was that the script started a vpn-connection and once this is established, I cannot mount the share any more. Therefore, whenever I tried the same command outside the script, it worked, whereas within the script it failed as it was executed after establishing the vpn-connection.
By moving the critical line above the line where the vpn connection was established, the share mounted correctly. Need to trouble-shoot somewhere else now. Thanks a lot for your help!

1 Like