我使用以下命令启动到远程 macOS 的 ssh 连接。目标是成功执行 ssh 登录并挂载特定网络共享(通过 mount.sh 脚本)。在远程 macOS 上存储和执行脚本 mount.sh工作正常。脚本接收用户输入并将其安装到用户定义的安装点中。但是每当我尝试通过 ssh 在远程系统上本地执行 script-mount.sh 时就会卡住。
事实上,ssh 登录工作正常,但 script-mount.sh 没有被执行。
#!/bin/bash
read -p "Enter Username: " username
ssh $username@<Server IP> "$(< mount.sh)"
欢迎任何改进代码的建议/建议:)。
mount.sh脚本代码:
#!/bin/bash
read -p "Enter the name of share mount :" lpmount
echo ""
read -p "Enter your User name: " username
echo ""
read -p "Enter the year (e.g. 2018,2019) :" year
mkdir /Gross/$lpmount
mount_smbfs //$username@<Server-IP>/Evi/$year /Gross/$lpmount
mount_status=$? # Checks if the mounting was successfull.
if [ $mount_status -eq 0 ]
then
echo ""
echo "Share mounted SUCCESSFULLY! at /Gross/$lpmount"
sleep 3
else
echo ""
echo " Share not mounted SUCCESSFULLY! at/Gross/$lpmount"
fi
答案1
解释:
您可以添加bash -s
将处理脚本的选项。请看下面的修改:
修改:
#!/bin/bash
read -p "Enter Username: " username
ssh $username@<Server IP> 'bash -s' < mount.sh