digitalx has asked for the wisdom of the Perl Monks concerning the following question:

Hello. I am new to perl and have been trying to write a script that will ease the tention of mounting a windows share from my linux box. I also wrote this script because since you give the password as an argument to the mount command it is echoed in plain text on the console. Therefore, I came up with this, what is in it's present state, useless script. The error I get when I try to use it is "Could not resolve mount point /mnt/win", where /mnt/win is obviously the mount point. When I use the command on the console all is well. Anyway, here is the code. Any help at all will be very helpful, me being the newb that I am.

#!/usr/bin/perl print "Enter the hostname of the computer: "; $hostname = <stdin>; print "Enter the sharname you wish to mount: "; $share = <stdin>; print "Enter a valid username: "; $username = <stdin>; print "Enter the password:"; system "stty -echo"; $password = <stdin>; system "stty echo"; print "\nSpecify a mount point?: "; $mntpoint = <stdin>; $options = "username=$username,password=$password"; system("mount", "-t", "smbfs", "-o", "$options", "//$hostname/$share", + "$mntpoint");

20030505 Edit by Corion: Changed formatting to use code tags

Replies are listed 'Best First'.
Re: Mounting windows shares from Linux
by allolex (Curate) on May 05, 2003 at 06:57 UTC

    A very good effort, but do you need Perl to do this? =)

    You might consider using smbmount with credentials in fstab instead of username and password, which solves the local echoing of the password. Essentially, what you do is create a file with two lines:

    username=Username password=Password

    somewhere in /etc. You then make sure owner and group are root, set permissions to 400, and add the credentials=/etc/yourfile to your options column.

    //windowsbox/windowshare /mnt/win smbfs noauto,credentials=/etc/yourfi +le 0 0
    You should also consider setting UID/GID in the options as well, to make sure that the unprivileged user mounting the share can also write to it.

    Cheers,

    --
    Allolex

    (update) PS: You need to chomp() your variables to get this script to work.

      Thanks for your help, it works perfetly now. Oh and I see that you were wondering why I was doing this. Well the reason I did not put it in my fstab is that this script is for my laptop so when I bring it to a friends or to school I need to mount on the fly. Again, many thanks!

        Glad to be able to help. BTW, you can still put mount points in fstab using the noauto option (like I did) and still mount your shares on the fly with mount /mnt/win or whatever. I guess that was the point I was trying to make with my main, alternative, suggestion.

        --
        Allolex

        The noauto option keeps the system from mounting the drive at system startup. The user option allows normal users to mount/dismount the drive. Put both in your fstab for this share and it should solve your problems.

        90% of every Perl application is already written.
        dragonchild
Re: Mounting windows shares from Linux
by cored (Scribe) on May 05, 2003 at 14:20 UTC
    Well i dont know why you are trying to make an script, cuz you can use the mount command, and if you want more automatization try using the fstab, just remember to add the smbfs on your kernel... i hope this help you