我刚刚通过更新我的挂载脚本提高了我的 Bash 技能,我想与世界分享它。如果您有任何想法,请在此处发布。
这是我的脚本:
#!/bin/bash
SDIR="/"
DIR="/home/MyUsername/fusessh/MyNetworkPC"
FMGR='thunar'
USER='MyUsername'
PASS='MyPassword'
IP[0]='192.168.0.100'
IP[1]='192.168.0.101'
IP[2]='192.168.0.102'
IP[3]='192.168.0.103'
PORT='-p 22'
if [ "$(ls -A $DIR)" ]; then
echo "$DIR is not Empty. And so it will be unmounted..."
fusermount -u $DIR
else
CURRENTIP=0
CONNECTED="False"
while [ "$CONNECTED" = "False" ] && [ $CURRENTIP -lt ${#IP[@]} ] ; do
if echo $PASS | sshfs $PORT -o ServerAliveInterval=15 -o password_stdin $USER@${IP[$CURRENTIP]}:$SDIR $DIR > /dev/null; then
echo "Mounted ${IP[$CURRENTIP]}:$SDIR to $DIR"
CONNECTED="True"
$FMGR $DIR &
else
echo "Could not mount ${IP[$CURRENTIP]}:$SDIR to $DIR"
let CURRENTIP+=1
fi
done
fi
exit 0