Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell expect脚本中的多个for循环_Shell_Loops_Unix_Expect - Fatal编程技术网

Shell expect脚本中的多个for循环

Shell expect脚本中的多个for循环,shell,loops,unix,expect,Shell,Loops,Unix,Expect,嗨,我不太擅长循环。有人能帮我了解sftp流程吗。脚本应该读取2个文件,一个有文件名,另一个有本地路径。脚本应该先执行一个循环,然后进入path1并从源到目标获取file1。但它只得到一个文件。我的意思是脚本或循环只执行了一次循环。你们能帮我吗。或者任何人都可以用其他方式来代替for循环。提前谢谢 The bkupdirs file contains: bkupdir1 bkupdir2 bkupdir3 dkupdir4 The backupfiles_list file contains:

嗨,我不太擅长循环。有人能帮我了解sftp流程吗。脚本应该读取2个文件,一个有文件名,另一个有本地路径。脚本应该先执行一个循环,然后进入path1并从源到目标获取file1。但它只得到一个文件。我的意思是脚本或循环只执行了一次循环。你们能帮我吗。或者任何人都可以用其他方式来代替for循环。提前谢谢

The bkupdirs file contains:
bkupdir1
bkupdir2
bkupdir3
dkupdir4
The backupfiles_list file contains:
bkupfile1
bkupfile2
bkupfile3
bkupfile4 

#!/usr/bin/expect -d
set sourceServer servername;
set f [open "/scripts/bkupdirs"]
set localbkuppaths [split [read $f] "\n"]
close $f
# Get the commands to run, one per line
set f [open "/dba/backupfiles_list"]
set srcbkupfiles [split [read $f] "\n"]
close $f

# Iterate over the hosts
foreach lbkuppath $localbkuppaths {
    spawn sftp id1@$sourceServer
    expect "password:"
    send "passwd\n";
    expect "sftp>"
    send "lcd $lbkuppath\n" 

# Iterate over the commands
foreach srcbkupfile $srcbkupfiles {
    expect "sftp>"
    send "get $srcbkupfile\n"
    expect "sftp>"
    send "bye\n"
}

# Tidy up
#    send "exit\n"
#    expect eof
#       interact
close
}

After the first iteration successfully it is not going to second value or 2nd iteration and have error msg like this:
send "bye\n"..."
("foreach" body line 10)
invoked from within
"foreach lbkuppath $localbkuppaths {
spawn sftp id1@$sourceServer
expect "password:"
send "passwd\n";
    expect "sftp>"
    send "lcd $l..."
(file "/db2dba/d1/master_scripts/sftpfull" line 13)

尝试将文件设置为不同的变量,如:

#!/usr/bin/expect -d
set f1 [open "/scripts/bkupdirs"]
set localbkuppaths [split [read $f1] "\n"]
close $f1
# Get the commands to run, one per line
set f2 [open "/dba/backupfiles_list"]
set srcbkupfiles [split [read $f2] "\n"]
close $f2