Score:0

How to convert text in except script?

sj flag

I'm trying to create a script that will answer questions in my other script on perl. There are simple actions but I cannot figure out how to make except understand the output.

Here's my code:

 #!/usr/bin/expect -f
 set force_conservative 0  ;
                           ;
 if {$force_conservative} {
         set send_slow {1 .1}
         proc send {ignore arg} {
                 sleep .1
                 exp_send -s -- $arg
         }
 }
 
 
 set timeout -1
 spawn /opt/kaspersky/klnagent64/lib/bin/setup/postinstall.pl
 match_max 100000
 expect "*Kaspersky Security Center 12 Web Console*
 \r"
 send -- "q\r"
 expect -gl "\r*\r
 Please*License\r
 Agreement*End\r
 User*Enter 'N'\r
 providing*or\r
 'R'*\[N\]: \r
 "
 send -- "Y\r"
 expect "Y\r
 Please enter Administration Server DNS-name or static IP-address\r
 "
 send -- "192.168.1.105\r"
 expect "192.168.1.105\r
 Please enter Administration Server port number \[14000\]: \r
 "
 send -- "\r"
 expect -exact "\r
 Please enter Administration Server ssl port number \[13000\]: \r
 "
 send -- "\r"
 expect -exact "\r
 Please enter 'Y' to confirm that you want to use SSL encryption\r
 or enter 'N' to use non-encrypted communication \[Y\]: \r
 "
 send -- "\r"
 expect -exact "\r
 The Network Agent being installed can be used as connection\r
 gateway. It will allow you to connect to Administration Server\r
 using the specified connection gateway.\r
 \r
 1) Do not configure connection gateway\r
 2) Do not use connection gateway\r
 3) Connect to server using connection gateway\r
 4) Use as connection gateway\r
 Please choose connection gateway mode: \[1\]: \r
 "
 send -- "2\
 expect eof

Error executing it:

 Fatal error: The End User License Agreement is not accepted!

 Kaspersky Network Agent is installed.
 Binaries were installed in /opt/kaspersky/klnagent64/bin
 send: spawn id exp4 not open
while executing
"send -- "Y\r""
(file "klnagent_new.exp" line 28)

I assume that there's problem expect understanding the text. Here's autoexpect code:

 #!/usr/bin/expect -f
 #
 # This Expect script was generated by autoexpect on Fri Nov 11 12:07:53 2022
 # Expect and autoexpect were both written by Don Libes, NIST.
 #
 # Note that autoexpect does not guarantee a working script.  It
 # necessarily has to guess about certain things.  Two reasons a script
 # might fail are:
 #
 # 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
 # etc.) and devices discard or ignore keystrokes that arrive "too
 # quickly" after prompts.  If you find your new script hanging up at
 # one spot, try adding a short sleep just before the previous send.
 # Setting "force_conservative" to 1 (see below) makes Expect do this
 # automatically - pausing briefly before sending each character.  This
 # pacifies every program I know of.  The -c flag makes the script do
 # this in the first place.  The -C flag allows you to define a
 # character to toggle this mode off and on.
 
 set force_conservative 0  ;# set to 1 to force conservative mode even if
                           ;# script wasn't run conservatively originally
 if {$force_conservative} {
         set send_slow {1 .1}
         proc send {ignore arg} {
                 sleep .1
                 exp_send -s -- $arg
         }
 }
 
 #
 # 2) differing output - Some programs produce different output each time
 # they run.  The "date" command is an obvious example.  Another is
 # ftp, if it produces throughput statistics at the end of a file
 # transfer.  If this causes a problem, delete these patterns or replace
 # them with wildcards.  An alternative is to use the -p flag (for
 # "prompt") which makes Expect only look for the last line of output
 # (i.e., the prompt).  The -P flag allows you to define a character to
 # toggle this mode off and on.
 #
 # Read the man page for more info.
 #
 # -Don
 
 
 set timeout -1
 spawn /opt/kaspersky/klnagent64/lib/bin/setup/postinstall.pl
 match_max 100000
 expect -exact "Kaspersky Security Center 12 Web Console, iOS MDM Server, Microsoft Exchange Mobile Devices Server, Administration Console, Kaspersky Security Center 12 Network Agent for Linux, Kaspersky Security      Center 12 Networ
 k Agent for Mac \r
 KASPERSKY LAB END USER LICENSE AGREEMENT\r
 \r
 BY CLICKING THE ACCEPT BUTTON IN THE LICENSE AGREEMENT WINDOW OR BY USING THE SOFTWARE YOU CONSENT TO BE BOUND BY THE TERMS AND CONDITIONS OF THIS AGREEMENT. SUCH ACTION IS A SYMBOL OF YOUR SIGNATURE AND YOU ARE      CONSENTING TO BE
 \r
 BOUND BY AND ARE BECOMING A PARTY TO THIS AGREEMENT AND AGREE THAT THIS AGREEMENT IS ENFORCEABLE LIKE ANY WRITTEN NEGOTIATED AGREEMENT SIGNED BY YOU. IF YOU DO NOT AGREE TO ALL OF THE TERMS AND CONDITIONS OF THIS      AGREEMENT, CANCE\r
 L THE INSTALLATION OF THE SOFTWARE AND DO NOT INSTALL THE SOFTWARE OR DO NOT USE THE SOFTWARE.\r
 \r
 IF LICENSE CONTRACT OR SIMILAR DOCUMENT ACCOMPANIES SOFTWARE, TERMS OF THE SOFTWARE USE DEFINED IN SUCH DOCUMENT PREVAIL OVER CURRENT END USER LICENSE AGREEMENT.\r
 \r
 1. Definitions\r
 1.1. Software means software Kaspersky Security Center 12 Web Console, iOS MDM Server, Microsoft Exchange Mobile Devices Server, Administration Console, Kaspersky Security Center 12 Network Agent for Linux,      Kaspersky Security Cen\r
 ter 12 Network Agent for Mac including any Updates and related materials.\r
 1.2. Rightholder (owner of all rights, whether exclusive or otherwise to the Software) means AO Kaspersky Lab, a company incorporated according to the laws of the Russian Federation.\r
 1.3. Computer(s) means combination of hardware(s), including personal computers, laptops, workstations, personal digital assistants, ‘smart phones’, hand-held devices, or other electronic devices, and operating      system(s) (includi\r
 ng system virtual machines) for which the Software was designed where the Software will be installed and/or used.\r
 1.4. End User (You/Your) means the organization for which the Software is downloaded or installed and it is represented hereby that such organization has authorized the person accepting this agreement to do so on      its behalf. For
 \r
 purposes hereof the term “organization”, without limitation, includes any partnership, limited liability company, corporation, association, joint stock company, trust, joint venture, labor organization,      unincorporated organizatio\r
 n, or governmental authority. If the Software was downloaded or installed on behalf of individual, End User (\"You\") further means such individual.\r
 1.5. Partner(s) means organizations or individual(s), who distributes the Software based on an agreement and license with the Rightholder.\r
 [7m--Далее--(15%)[27m"
 send -- "q"
 expect -exact "\r[K\r
 Please enter 'Y' to confirm that you accept the End User License\r
 Agreement. You must accept the terms and conditions of the End\r
 User License Agreement to install the application. Enter 'N'\r
 providing you do not accept the End User License Agreement or\r
 'R' to show it again \[N\]: \r
 "
 send -- "Y\r"
 expect -exact "Y\r
 Please enter Administration Server DNS-name or static IP-address\r
 "
 send -- "192.168.1.105\r"
 expect -exact "192.168.1.105\r
 Please enter Administration Server port number \[14000\]: \r
 "
 send -- "\r"
 expect -exact "\r
 Please enter Administration Server ssl port number \[13000\]: \r
 "
 send -- "\r"
 expect -exact "\r
 Please enter 'Y' to confirm that you want to use SSL encryption\r
 or enter 'N' to use non-encrypted communication \[Y\]: \r
 "
 send -- "\r"
 expect -exact "\r
 The Network Agent being installed can be used as connection\r
 gateway. It will allow you to connect to Administration Server\r
 using the specified connection gateway.\r
 \r
 1) Do not configure connection gateway\r
 2) Do not use connection gateway\r
 3) Connect to server using connection gateway\r
 4) Use as connection gateway\r
 Please choose connection gateway mode: \[1\]: \r
 "
 send -- "2\r"
 expect eof

I see the problem at the section: Please enter 'Y' to confirm that you accept the End User License\r Agreement. You must accept the terms and conditions of the End\r User License Agreement to install the application. Enter 'N'\r providing you do not accept the End User License Agreement or\r 'R' to show it again [N]: \r I tried different ways using \r, *, ^ etc. All failed. I'd rather use autoexpect but it's execution depends on this "[7m--Далее--(15%)[27m"" Any advices wewlcome.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.