【问题标题】:Expect : How to create a remote directory thru ssh command期望:如何通过 ssh 命令创建远程目录
【发布时间】:2016-02-25 13:21:27
【问题描述】:

我正在尝试使用以下期望脚本在远程服务器中创建目录,但出现错误

spawn ssh  $username@$ipaddress 'mkdir $destination/$dir_to_be_copied'
expect "?assword:"
send "$password\r"
expect eof

但我收到以下错误

mkdir <MY NEW DIRECTORY>: No such file or directory

【问题讨论】:

  • 单引号不是必须的。

标签: linux shell ssh tcl expect


【解决方案1】:

单引号(')在Tcl/Expect 中并不特殊,所以你应该写

spawn ssh $username@$ipaddress "mkdir $destination/$dir_to_be_copied"

或者只是

spawn ssh $username@$ipaddress mkdir $destination/$dir_to_be_copied

【讨论】:

    【解决方案2】:

    我猜这个问题不是因为Expect。从错误消息来看,$destination 文件夹本身很可能不可用。 先检查一下。

    试试这个

    mkdir -p $destination/$dir_to_be_copied

    【讨论】:

      猜你喜欢
      • 2018-04-21
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多