Use expect here Document in shell

Source: Internet
Author: User

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 




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.