【问题标题】:SCP used with find anc -ctime in expect script does not work在期望脚本中与 find anc -ctime 一起使用的 SCP 不起作用
【发布时间】:2016-08-21 08:04:17
【问题描述】:

我之前已经发布了类似的问题并得到了一些帮助,我将其更改为该问题,但仍然无法正常工作。我正在尝试 scp 到远程位置并从一天前获取最新文件。当我自己运行命令时它可以工作。

脚本如下所示:

#!/usr/bin/expect -f
exp_internal 1
set host_ip [lindex $argv 0 ]
set user [lindex $argv 1 ]
set password [lindex $argv 2]
set scp_remote_directory [lindex $argv 3 ]
set local_directory [lindex $argv 4]

set force_conservative 1  ;# set to 1 to force conservative mode even if
                          ;# script was not run conservatively originally
if {$force_conservative} {
        set send_slow {1 .1}
        proc send {ignore arg} {
                sleep .1
                exp_send -s -- $arg
        }
}

set timeout -1
#spawn scp $user@$host_ip:$scp_remote_directory/$scp_remote_filename $local_directory/
#spawn rsync -azv $user@$host_ip:\´\$(find\ $scp_remote_directory\ -ctime\ -1\ )\´ $local_directory/
#spawn scp $user@$host_ip:\'\$(find\ $scp_remote_directory\ -ctime\ -1)\' $local_directory/
spawn scp $user@$host_ip:\`\$(find\ $scp_remote_directory\ -ctime\ -1\ )\` $local_directory/
#spawn scp $user@$host_ip:$scp_remote_directory/CscfHealthCheckReport_$TagID_$phase* $local_directory/
match_max 100000
expect {
  -exact "Are you sure you want to continue connecting (yes/no)? " {
    send -- "yes\r"
    exp_continue
  }
  -exact "${user}@${host_ip}'s password: " {
    send -- "$password\r"
  }
  -exact "Password: " {
    send -- "$password\r"
  }
}
expect eof

它抱怨权限,但这不是权限问题。如果我将 SCP 行 ` 更改为 ' 我会遇到另一个问题。

这里是打印输出:

/td_general_scp.exp 10.33.122.22 root rootroot /cluster/storage/no-backup/coremw/var/log/saflog/FaultManagementLog/alarm/Fm*.log /home/imstest/shared/Generate/ReportingT3/tmp
spawn scp root@10.33.122.22:`$(find /cluster/storage/no-backup/coremw/var/log/saflog/FaultManagementLog/alarm/Fm*.log -ctime -1 )` /home/imstest/shared/Generate/ReportingT3/tmp/
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {141218}

expect: does "" (spawn_id exp6) match exact string "Are you sure you want to continue connecting (yes/no)? "? no
"root@10.33.122.22's password: "? no
"Password: "? no
Password: 
expect: does "Password: " (spawn_id exp6) match exact string "Are you sure you want to continue connecting (yes/no)? "? no
"root@10.33.122.22's password: "? no
"Password: "? yes
expect: set expect_out(0,string) "Password: "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "Password: "
send: sending "rootroot\r" to { exp6 }

bash: /cluster/storage/no-backup/coremw/var/log/saflog/FaultManagementLog/alarm/FmAlarmLog_20160422_152507_20160426_135452.log: Permission denied
expect: read eof
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "\r\nbash: /cluster/storage/no-backup/coremw/var/log/saflog/FaultManagementLog/alarm/FmAlarmLog_20160422_152507_20160426_135452.log: Permission denied\r\n"

脚本的名称是 td_general_scp.exp

感谢您的帮助。

【问题讨论】:

    标签: bash scripting find expect scp


    【解决方案1】:

    远程 shell 执行$(find ...) 并发出文件名。那就是找到。

    但是您将其用反引号括起来,因此您现在正尝试将 find 输出作为脚本执行

    您可能想离开 scp 并改用 rsync。

    【讨论】:

    • 嗨,格伦,感谢您的输入,但我也尝试了 rsync。我在这个链接中有一个类似的问题。相同类型的错误检查一下。 link 我在它周围加上了勾号,因为我得到了关于那个问题的建议。
    猜你喜欢
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 2017-12-31
    • 2023-03-12
    • 1970-01-01
    • 2014-11-05
    相关资源
    最近更新 更多