【问题标题】:Shell script that SSH's into another machine, runs another script, 2nd script asks for user inputSSH进入另一台机器的Shell脚本,运行另一个脚本,第二个脚本要求用户输入
【发布时间】:2014-06-27 03:32:22
【问题描述】:
ssh -t -t me@myothermachine.ca<<EOF
cd ../../path/to/script/directory/
sh copyfiles.sh
cd ../../copied/directory
sh renamer.sh
exit
EOF

大家好,

上面的脚本是我正在使用的。 copyfiles.sh 有一个“读取”,询问我要复制的文件的年份和月份。它将复制的文件在标题中有年份和月份,因此它会查看文件的标题并查找用户输入的该年份和月份的所有文件。您可能更容易只看一下代码以了解它实际上在做什么。在这里。

#get the year and the month from the user
echo "Please enter the year"
read year
echo "Please enter the month"
read month

files=`find . -name "*$year*$month*.txt"`

for file in $files; do
    cp $file /the/copy/to/directory
done

我遇到的问题是我在询问时输入“2014”,然后就挂起。

它登录到我的另一台机器,显示我初始脚本的中间 5 行代码,然后开始将它们作为命令读取。它 cd 正确,然后进入 sh copyfiles.sh 脚本,它询问年份,我输入年份,然后挂起。

这样的用户输入用 shell 脚本不可行吗?

【问题讨论】:

    标签: shell ssh nested


    【解决方案1】:

    你不能那样做。如果您有copyfiles.sh 的源,您应该修改它,以便您可以将所需的输入作为参数传递给copyfiles.sh。然后,您的 ssh 会话可以为您执行它,例如

    ssh -t -t me@myothermachine.ca<<EOF
        cd ../../path/to/script/directory/
        sh copyfiles.sh --year 2014 --month june
        cd ../../copied/directory
        sh renamer.sh
        exit
    EOF
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-10
      • 2020-11-04
      相关资源
      最近更新 更多