Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: mount from remote system using fuse and sshfs, utility script mount remote filesys< Next Oldest | Next Newest >
fredvej Offline





Group: Members
Posts: 12
Joined: June 2006
Posted: Feb. 26 2007,18:34 QUOTE

Here's a script to mount something from a remote system running an SSH server.  On your local machine you need a mountpoint, load the fuse module and mount using sshfs.
Code Sample

# script mounts a path from a remote system using fuse and sshfs

THISPROG=`basename $0`
PUBLICIP=12.34.56.78
LOCALIP=192.168.0.2
SSHPORT=22

USAGE="
Usage : $THISPROG [options] {username} {remote path to mount} {local mount point}

local mount point must be an existing directory

options :

-r {IP address} : use IP adress for remote host , e.g. -r 123.45.67.89
  Default remote IP is $PUBLICIP

-p {port number} : Port number to use for ssh connection , default $SSHPORT

-l {IP address | d} : remote host at local LAN , no caching.
  Use provided IP address or default (d) $LOCALIP
"

############ FUNCTIONS ######################

Exit_if_Error ()
{
 if [ $RETURN -ne 0 ]
 then
   echo "$COMMAND failed with return code $RETURN"
   exit $RETURN
 fi
}

LoadModule ()
{
 MOD2LOAD=$1
 ISLOADED=`lsmod | grep $MOD2LOAD`
 if [ -z "$ISLOADED" ]
 then
   COMMAND="$SUDO /sbin/modprobe -v $MOD2LOAD"
   echo "probing module with $COMMAND"
   $COMMAND
   RETURN=$?
   Exit_if_Error
 fi
}

############ MAIN ###########################

# follow_symlinks not in DSL 3.2 #FSOPTIONS="-o compression=yes,transform_symlinks,follow_symlinks,allow_other,nonempty"
FSOPTIONS="-o compression=yes,transform_symlinks,allow_other,nonempty"
HOSTIP=$PUBLICIP

while getopts 'r:p:l:hH' OPTION
do
 case $OPTION in
 r)
    HOSTIP=$OPTARG
 ;;
 l)
   HOSTIP=$OPTARG
   if [ "$HOSTIP" = "d" ]
   then
     HOSTIP=$LOCALIP
   fi
   FSOPTIONS="${FSOPTIONS},sshfs_sync,no_readahead,cache=no"
 ;;
 p)
   SSHPORT=$OPTARG
 ;;
 h|H)
   echo "$USAGE"
   exit 1
 ;;
 *)
   echo "$USAGE"
   exit 1
 ;;
 esac
done

shift `expr $OPTIND - 1`
FSOPTIONS="-p $SSHPORT $FSOPTIONS"

LOGINAS=$1
RPATH="$2"
MPOINT="$3"

if [ $# -ne 3 ]
then
 echo "
Number of parameters must be 3 - aborting !"
 echo "$USAGE"
 exit 1
fi

USELOGIN="${LOGINAS}@"

if [ ! -d "$MPOINT" ]
then
 echo "
mount point '$MPOINT' is not found or is not a directory - aborting !"
 echo "$USAGE"
 exit 2
fi

USERID=`id -u`
if [ "$USERID" = "0" ]
then
 SUDO=""
else
 SUDO=/usr/bin/sudo
 if [ -n "$FSOPTIONS" ]
 then
# local uid on local mountpoint, remote user's id on remote filesystem
   FSOPTIONS="${FSOPTIONS},uid=$USERID"
 fi
fi

LoadModule fuse

COMMAND="$SUDO sshfs \"${USELOGIN}${HOSTIP}:${RPATH}\" \"$MPOINT\" ${FSOPTIONS}"
echo "mounting with $COMMAND"
$SUDO sshfs "${USELOGIN}${HOSTIP}:${RPATH}" "$MPOINT" ${FSOPTIONS}
RETURN=$?
Exit_if_Error


Unmount :
Code Sample
sudo fusermount -u $MPOINT


Enjoy


--------------
/Freddy
Back to top
Profile PM YIM 
fredvej Offline





Group: Members
Posts: 12
Joined: June 2006
Posted: Feb. 28 2007,15:18 QUOTE

Sorry, follow_symlinks is not recognised by DSL as an sshfs option.

Correction to the script :
FSOPTIONS="-o compression=yes,transform_symlinks,allow_other,nonempty"


--------------
/Freddy
Back to top
Profile PM YIM 
1 replies since Feb. 26 2007,18:34 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: mount from remote system using fuse and sshfs

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code