我之前已经发布了类似的问题并获得了一些帮助,我将其更改为了但仍然无效。我正在尝试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
感谢您的帮助。
答案 0 :(得分:0)
远程shell执行$(find ...)
并发出文件名。找到了。
但是你在反引号中围绕它,所以你现在正试图执行将查找输出作为脚本。
您可能希望远离scp并改为使用rsync。