Results 1 to 8 of 8

Thread: Automating sshfs command

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Beans
    1

    Automating sshfs command

    I've been trying write an automation script for sshfs using expect and also pexpect. I can't seem to get it right. Does anybody know how to get the sshfs automation working?

    This is what i want to do:
    Given a username and a password, i want the script to mount the home directory for the username given, at a location on the local machine.

    ex: sshfs me@192.168.0.10: /home/thisuser/mountpoint

    I don't want a solution using certificates, and automaticly logon to ssh. I wan't to get this working using only scripting.

    Anyone?

  2. #2
    Join Date
    Feb 2006
    Beans
    223
    Distro
    Kubuntu Karmic Koala (testing)

    Re: Automating sshfs command

    Sorry about bringing this post back from the dead so to speak, but I was having the same problem myself.

    Anyway once I downloaded pexpect I wrote a quick and dirty python script to connect.

    PHP Code:
     #!/usr/bin/python
    import pexpect
    import time

    command 
    "sshfs username@server:/path/to/home/folder /mount/point/"

    def start_sshfs():
        try:
            
    sshfs pexpect.spawn(command)
            
    sshfs.expect("Password: ")
            
    time.sleep (0.1)
            
    sshfs.sendline ("YourPassword")
            
    time.sleep (10
            
    sshfs.expect (pexpect.EOF)

        
    except Exceptione:
            print 
    str(e)

    def main ():
        
    start_sshfs()

    if 
    __name__ == '__main__':
        
    main () 
    Hope this helps someone.

    Of course this has some security issues as you are storing a password in plain text. So remember to guard against that.
    George
    Last edited by gmclachl; September 9th, 2006 at 08:16 PM.

  3. #3
    Join Date
    Jan 2006
    Location
    Trollhättan Sweden
    Beans
    19
    Distro
    Kubuntu Breezy 5.10

    Re: Automating sshfs command

    How do I use this script?

  4. #4
    Join Date
    Jul 2007
    Location
    Belgium
    Beans
    10
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Automating sshfs command

    up!

  5. #5
    Join Date
    Oct 2004
    Location
    Pennsylvania
    Beans
    1,698

    Re: Automating sshfs command

    Quote Originally Posted by HakanS View Post
    How do I use this script?
    You have to change the line starting with "command =" to have the correct command to mount the sshfs filesystem (e.g. replace the username, server, path to remote folder, and local mount point). You also need to replace "YourPassword" with the actual password used to log on. This is why the original poster cautions that you would have to have your password in plain-text in the script.

  6. #6
    Join Date
    Aug 2008
    Location
    Sweden
    Beans
    249
    Distro
    Ubuntu 12.04 Precise Pangolin

    Thumbs up Re: Automating sshfs command

    I've made an update of this script.. So it will work in Karmic. And with the newest update of sshfs.

    PHP Code:
    #!/usr/bin/python
    import pexpect
    import time

    username 
    "username"
    password "password"
    host "adress.for.the.host"
    hostdirectory "/path/on/host"
    mountpoint "/path/to/mountpoint"

    command "sshfs " username "@" host ":" hostdirectory " " mountpoint

    def start_sshfs
    ():
        try:
            
    sshfs pexpect.spawn(command)
            
    sshfs.expect(username "@" host "'s password: ")
            
    time.sleep (0.1)
            
    sshfs.sendline (password)
            
    time.sleep (10
            
    sshfs.expect (pexpect.EOF)

        
    except Exceptione:
            print 
    str(e)

    def main ():
        
    start_sshfs()

    if 
    __name__ == '__main__':
        
    main () 
    Hope that this will soon be a native feature of the Ubuntu distro. Just a little checkbox when you mount a network/ssh path. "Automount this on startup"

    Cheers,
    Artheus
    Ubuntu server ed. 12.04 x64

  7. #7
    Join Date
    Oct 2007
    Location
    Melbourne, Australia
    Beans
    6
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Automating sshfs command

    Great solution from http://darklaunch.com/2009/06/05/how...mounting-mosso

    Code:
    echo mypassword | sshfs myuser@ftp.mysite.com:/ ~/mounts/mysite -o workaround=rename -o password_stdin

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •