You are not logged in.

#1 2009-06-25 13:12:00

Revolt
Member
From: Portugal
Registered: 2009-06-11
Posts: 71
Website

sshfs connect bash + expect script

Hey there!

I've been trying to develop a script that would allow automatic mounting of a FTPS server, opening of pcmanfm and, on its closure, unmount the server.

Currently, it is split in two files (one interpreted by bash and the other interpreted by expect):

#!/bin/bash
# Connect to wireless network phoenix at home

password=$(zenity --title "SSH Password" --entry --text "Password:")
./mount-ftp-acid-dev $password

pcmanfm /mnt/ftp/domain
fusermount -u /mnt/ftp/domain
#!/usr/bin/expect
# Mount Acid Lounge Devel FTP

set password [lrange $argv 0 0]
set timeout 60 

spawn sshfs revolt@domain:/ /mnt/ftp/domain -C -p 22
expect "*?assword*"
send -- "$password\r"
expect "\r"

The problem is that the second script doesn't seem to work. If I execute sshfs... manually and enter the password on the terminal it works fine. However, when I execute that script, I see sshfs asking for the password and then the 'send' command does its thing and sshfs exits. However, if I go to the mount folder it is empty :X Even if I just execute the 2nd script and put the password directly on the 'send' command it seems to fail. What might be causing this?

Appreciate all the help you can give me smile

Last edited by Revolt (2009-06-25 13:12:44)

Offline

#2 2009-06-26 21:08:08

Revolt
Member
From: Portugal
Registered: 2009-06-11
Posts: 71
Website

Re: sshfs connect bash + expect script

Ok following this topic which kinda reflects my situation I was able to get it working:
http://ubuntuforums.org/showthread.php?t=577454

Only problem now is that the bash script only functions properly if there's no open instance of pcmanfm. Otherwise it races through the pcmanfm call (I guess it uses the already created process instead of creating a new one) and unmounts the folder. A possible solution for this would be to use a separate file manager but this would be a bloated solution. Any good ideas?

Offline

#3 2009-06-27 23:56:04

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: sshfs connect bash + expect script

Why not just check in your script if pcmanfm is running, and make further file manager calls depend on that?

You can easily use

pgrep pcmanfm

which evaluates by itself, so you can do

pgrep pcmanfm && echo "Dude I'm still here"

or

pgrep pcmanfm || pcmanfm --options

Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#4 2009-06-28 00:09:35

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: sshfs connect bash + expect script

For the sshfs piece, you would be better off using keys instead of passwords.

Offline

#5 2009-06-28 12:15:21

Revolt
Member
From: Portugal
Registered: 2009-06-11
Posts: 71
Website

Re: sshfs connect bash + expect script

tomk wrote:

For the sshfs piece, you would be better off using keys instead of passwords.

Why? Just for the convenience of not having to type it everytime or is there another reason concerning security?

And regarding B's suggestion, I could indeed check if it already running but it doesn't really help me in this case. Unless there's a way to 'monitor' the running pcmanfm process and wait till it closes before unmounting wink

Offline

#6 2009-06-28 14:06:20

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: sshfs connect bash + expect script

Security, yes, but in this case convenience also, as you don't have to concern yourself with scripting the password negotiation stage.

Offline

#7 2009-10-08 12:34:33

DanielSmedegaardBuus
Member
Registered: 2009-10-08
Posts: 2

Re: sshfs connect bash + expect script

Hey guys, just for the record, you don't really have to complicate the thing with expect here. If you provide the password_stdin option to sshfs, you can simply pipe in the password on the command line, like so:

echo myverysecretpasswordpleasedontstealme | sshfs me@myserver:/home/me/Music /home/me/Music -o follow_symlinks,password_stdin,uid=1000,gid=1000,umask=555

Voila wink

Offline

#8 2009-10-08 13:11:41

fijam
Member
Registered: 2009-02-03
Posts: 244
Website

Re: sshfs connect bash + expect script

Or... you could use autofs+sshfs and treat your remote server just like any other directory.

Offline

#9 2009-10-16 10:32:43

DanielSmedegaardBuus
Member
Registered: 2009-10-08
Posts: 2

Re: sshfs connect bash + expect script

Except that would be off-topic for this question, as that would still require you to either supply a password or set up key file authentication.

Offline

Board footer

Powered by FluxBB