When you use a shell to write a program, you sometimes have to confront the problem of interaction--unfortunately, the shell can't automatically complete the interaction. If the interactive content is many, it is convenient to apply expect script directly, if the content of interaction is very small, and considering the usability of shell, it is more convenient and flexible to create a expect here document in the shell script.
As shown in the following example, Expect here document can be run directly and assign the results of the run to the Ksh variable rcs_stat.
#!/bin/ksh autoload formatapnum # Set The lab name, Coollab. $COOLXDIR/.netlabs # get the RCS cell List set-a rcss typeset-i nx=0 cat $COOLXDIR/.coolcell2dcs | While the Read cell do if [[$cell] = c*]] then rcs=${cell%% $COOLLAB *} rcss[$nx]=${rcs#c} nx= $nx +1 fi Done # Check RCS status Typeset-i loopcount=0 rcs_cnt=${#RCSs [*]} b_server=$ (Formatapnum $BserverAP) while ["${#RCSs [*]}"!= 0-a $l OOPCOUNT-LT 720] # wait in most 2 hours do loopcount=${loopcount}+1 nx=0 while [$nx-lt $rcs _cnt] do rcs_stat= "OOS" rcs_stat=$ (expect-<<! log_user 0 Set timeout spawn $COOL _rsh ap$b_server ticli send "Op:cell ${rcss[$n
X]}\r ' Expect {timeout {puts ' oos\n '} ' *dl (s) down ' {puts ' oos\n '} ' *dl (S) up ' {puts ' up\n '}}!
The IF ["$rcs _stat" = "Up"] then Coolprint-"RCS cell ${rcss[$nx]} are up." unset rcss[$nx] fi nx=${nx}+1 done [-N "${rcss[*]}"] && sleep did Coolprint-"all rcss are up." E XIT 0