我想挂载:
remote:/media/user/directory
进入:
/media/user/directory
但是当远程目录名和本地目录名相同时,安装失败。发出mount命令反映了这一点。
但是,如果我使用相同目标目录名称的任何其他变体,它将按预期工作。范例:
/media/user/.directory # Succeeds.
/media/user/_directory # Succeeds.
/media/user/$(hostname)_directory # Succeeds.
/media/user/directory # Fails: same as `remote:dir`.
是否在内部防止匹配本地和远程目录名称?
我在某个地方犯了语法错误吗?
这是否有点不可思议的用法:
ssh -q $host mount </dev/null
也:
这是实际脚本的简化摘要,因此此处没有显示健全性检查。
由于~/.ssh/config
别名,我通常不需要在我的ssh主机名中包含user @,但包括它们没有任何区别。
代码:
#!/bin/bash
hostnameList='
hostnameA
hostnameB
hostnameC
'
while read host; do
if [[ -n $host && "$host" != "$(hostname)" ]]; then
availableRemoteDirs=$(ssh -q $host mount < /dev/null \
| grep "/media" | grep -v "fuse.sshfs" \
| awk -F' on |:| ' '{print $1 " " $2}' \
| sed 's/^[^/].*//; s/^.* //'
)
while read remoteDir; do
if [[ -n "$remoteDir" ]]; then
localDir="${remoteDir}" # FAILS - but is the required name
# localDir="${remoteDir%/*}/${host}_${remoteDir##*/}" # works
# localDir="${remoteDir%/*}/_${remoteDir##*/}" # works
mkdir --verbose --parent "$localDir" &> /dev/null
sshfs $host:$remoteDir $localDir \
-o debug,sshfs_debug,idmap=user,nonempty,compression=no &
sleep 1s
test=$(mount | grep fuse.sshfs | grep "$localDir")
echo "test: $test"
if [[ -n $test ]]; then
echo "OK: $host:$remoteDir -> $localDir"
else
echo "Fail"
fi
fi
done <<< "$availableRemoteDirs"
fi
done <<< "$hostnameList"
根据要求:添加错误消息/日志。
注意:最后两个命令中没有错误指示,我已删除了调试选项。
注意:在第二次成功的挂载中; “唯一:1,成功,超出尺寸:40”之后的文字是因为我刷新了(F5)我正在查看安装位置的Dolphin目录。
user@betlogbeast:~$ sshfs betlognuc:/media/user/data-backup /media/user/data-backup -o debug,sshfs_debug,idmap=user,nonempty
SSHFS version 2.8
FUSE library version: 2.9.7
nullpath_ok: 0
nopath: 0
utime_omit_ok: 0
executing <ssh> <-x> <-a> <-oClearAllForwardings=yes> <-2> <betlognuc> <-s> <sftp>
Authenticated to 192.168.188.20 ([192.168.188.20]:22).
Server version: 3
Extension: [email protected] <1>
Extension: [email protected] <2>
Extension: [email protected] <2>
Extension: [email protected] <1>
Extension: [email protected] <1>
sent: 0 messages, 0 bytes
received: 0 messages, 0 bytes
rtt min/max/avg: 0ms/0ms/0ms
num connect: 1
user@betlogbeast:~$ Transferred: sent 8308, received 4560 bytes, in 0.3 seconds
Bytes per second: sent 30241.8, received 16598.8
^C
user@betlogbeast:~$ sshfs betlognuc:/media/user/data-backup /media/user/betlognuc_data-backup -o debug,sshfs_debug,idmap=user,nonempty
SSHFS version 2.8
FUSE library version: 2.9.7
nullpath_ok: 0
nopath: 0
utime_omit_ok: 0
executing <ssh> <-x> <-a> <-oClearAllForwardings=yes> <-2> <betlognuc> <-s> <sftp>
Authenticated to 192.168.188.20 ([192.168.188.20]:22).
Server version: 3
Extension: [email protected] <1>
Extension: [email protected] <2>
Extension: [email protected] <2>
Extension: [email protected] <1>
Extension: [email protected] <1>
unique: 1, opcode: INIT (26), nodeid: 0, insize: 56, pid: 0
INIT: 7.26
flags=0x001ffffb
max_readahead=0x00020000
remote_uid = 1000
INIT: 7.19
flags=0x00000011
max_readahead=0x00020000
max_write=0x00020000
max_background=0
congestion_threshold=0
**unique: 1, success, outsize: 40**
unique: 2, opcode: GETATTR (3), nodeid: 1, insize: 56, pid: 24357
getattr /
[00002] LSTAT
[00002] ATTRS 41bytes (0ms)
unique: 2, success, outsize: 120
unique: 3, opcode: GETXATTR (22), nodeid: 1, insize: 72, pid: 24357
unique: 3, error: -38 (Function not implemented), outsize: 16
unique: 4, opcode: LOOKUP (1), nodeid: 1, insize: 51, pid: 31277
LOOKUP /.directory
getattr /.directory
[00003] LSTAT
[00003] ATTRS 41bytes (0ms)
NODEID: 2
unique: 4, success, outsize: 144
unique: 5, opcode: ACCESS (34), nodeid: 2, insize: 48, pid: 31277
access /.directory 02
unique: 5, success, outsize: 16
unique: 6, opcode: OPEN (14), nodeid: 2, insize: 48, pid: 31277
open flags: 0x8000 /.directory
[00004] OPEN
[00005] LSTAT
[00004] HANDLE 17bytes (0ms)
[00005] ATTRS 41bytes (0ms)
open[139944597131952] flags: 0x8000 /.directory
unique: 6, success, outsize: 32
unique: 7, opcode: READ (15), nodeid: 2, insize: 80, pid: 31277
read[139944597131952] 4096 bytes from 0 flags: 0x8000
[00006] READ
[00006] DATA 295bytes (0ms)
read[139944597131952] 282 bytes from 0
unique: 7, success, outsize: 298
unique: 8, opcode: GETATTR (3), nodeid: 2, insize: 56, pid: 31277
fgetattr[139944597131952] /.directory
unique: 8, success, outsize: 120
unique: 9, opcode: FLUSH (25), nodeid: 2, insize: 64, pid: 31277
flush[139944597131952]
unique: 9, success, outsize: 16
unique: 10, opcode: RELEASE (18), nodeid: 2, insize: 64, pid: 0
release[139944597131952] flags: 0x8000
[00007] CLOSE
unique: 10, success, outsize: 16
unique: 11, opcode: OPENDIR (27), nodeid: 1, insize: 48, pid: 31280
unique: 11, success, outsize: 32
unique: 12, opcode: READDIR (28), nodeid: 1, insize: 80, pid: 31280
getdir[0]
[00008] OPENDIR
[00007] STATUS 28bytes (0ms)
[00008] HANDLE 17bytes (0ms)
[00009] READDIR
[00010] READDIR
[00009] NAME 13119bytes (3ms)
[00011] READDIR
[00012] READDIR
[00010] NAME 1681bytes (3ms)
[00013] READDIR
[00014] READDIR
[00011] STATUS 32bytes (0ms)
[00012] STATUS 32bytes (0ms)
[00013] STATUS 32bytes (0ms)
[00014] STATUS 32bytes (0ms)
[00015] CLOSE
unique: 12, success, outsize: 4112
unique: 13, opcode: READDIR (28), nodeid: 1, insize: 80, pid: 31280
unique: 13, success, outsize: 864
unique: 14, opcode: READDIR (28), nodeid: 1, insize: 80, pid: 31280
unique: 14, success, outsize: 16
unique: 15, opcode: RELEASEDIR (29), nodeid: 1, insize: 64, pid: 0
unique: 15, success, outsize: 16
[00015] STATUS 28bytes (0ms)
^C
Killed by signal 2.
remote host has disconnected
Terminated
user@betlogbeast:~$ ^C
user@betlogbeast:~$ sshfs betlognuc:/media/user/data-backup /media/user/betlognuc_data-backup -o idmap=user,nonempty
user@betlogbeast:~$ sshfs betlognuc:/media/user/data-backup /media/user/data-backup -o idmap=user,nonempty
user@betlogbeast:~$
[一种可能是hostnameList
列表中列出的主机之一是运行脚本的主机。换句话说,您正在尝试通过自身在本地主机上挂载目录。