Rinky Rinky - 3 months ago 15
Bash Question

Set timeout for expect script if execution time is input based

I have an expect script, which executes remote shell script.Now the time taken to execute shell script is based on inputs. More input, more time, less input less time.How should I set my timeout value because if set timeout as -1, then it will exit only with eof, and in case script gets hanged, then we will have a hanged session.

Answer

After analyzing the output pattern of the ongoing script, I found "OK" coming for all the lines read from the input file.So, I used it as a progress indicator to reset my timeout counter. Following is the fraction of code I wrote to resolve my problem :

send -- "bash scriptname.sh \r"
expect {
         -re "OK" {
                  exp_continue
                  }
         -re "Enter XYZ value:" {
                                   send "0000\r"
                                   }
         timeout {
                 exit
                 }
         eof     {
                 exit
                 }
       }
Comments