【问题标题】:bash and expect - doesn't take port while rsyncingbash 和 expect - rsync 时不占用端口
【发布时间】:2013-10-29 17:23:22
【问题描述】:

我有一个如下的简单脚本,它使用expect 来同步一些数据(通过 ssh)。代码如下:

local_path1="/root/accordingtojim.txt"
username="ih4d35"
ip="10.0.0.152"
port="22"
password="t3tr@h3dr0n"

echo "$local_path1 $username $ip $port $password"

expect -c 'spawn rsync -avz -e "ssh -p $port" $local_path1 $username\@$ip:~/; expect '*?assword:*' {send \"$password\r\"; interact};'

这是我得到的错误:

can't read "port": no such variable
    while executing
"spawn rsync -avz -e "ssh -p $port" $local_path1 $username\@$ip:~/"

echo 语句工作正常。

我做错了什么?

【问题讨论】:

    标签: bash ssh expect rsync


    【解决方案1】:

    Shell 变量不会在单引号之间展开,所以去掉它们并将嵌套的引号替换为转义的引号:

    expect -c "spawn rsync -avz -e \"ssh -p $port\" $local_path1 $username\@$ip:~/; expect '*?assword:*' {send \"$password\r\"; interact};"
    

    【讨论】:

      猜你喜欢
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-31
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多