File expect_ssh_scp. Sh
#! The/usr/bin/expect # said to use expect the interpreter
Set the timeout of 10 # set the timeout limit for 10 seconds
Spawn SSH userName @ hremote_host command # via SSH to connect to a remote host execute the command
Expect the first expect {# statement
"(yes/no)" {send "yes \ r"; Exp_continue}
"* assword: {the send password \ r"}
}
Expect eof # indicates that the command interaction end
Spawn SCP source userName @ the hostName: dest # by SCP copy remote computer file to the local
Expect {# expect the second statement
"(yes/no)" {send "yes \ r"; Exp_continue}
"* assword: {the send password \ r"}
}
Expect 100%
Expect eof
The exit
I want to know the timeout 10 seconds, is effective for all expect statements, or only for the first?
If timeout limit to expect of all of the following statements are valid, such as the SCP remote replication command below, if the data have not finished transfer, application timeout, then how to solve?
So expect 100% code and what is the role of the sentence??
I saw one explanation is that: the beginning of the code to set the timeout time for 10 seconds, if in performing the duty of SCP met code does not specify exceptions, are waiting for 10 seconds after the execution of the script will be automatically terminated, understand it right?
Why this timeout period, the feeling is very affect the efficiency of the program, met in the execution of problem return information, exit is not good, even if to 10 seconds, still not solved, is just like the exception handling mechanism in the Java, found abnormal, throw the catch processing, and then continue to execute program, this much good,
If one method is very time consuming, then wait for it after bai, even if one day, an infinite loop this method of execution of the forever, set a timeout, so that the logic of feeling right, in an infinite loop problem is clearly about the design of the
CodePudding user response:
Any friends know, explain ah, thank youCodePudding user response:
https://blog.csdn.net/beibei0921/article/details/45370363