Expect is an interesting utility that allows interactive sessions to be scripted. Unlike here documents, expect scripts can implement conditional scripts based on the output of the program which they are interacting with. I saw this utility used in a Dell whitepaper on SAN snapshot management and vowed to investigate it when I had the chance.
Expect was not installed by default in my OEL5U6 VM, but it was included in the software distribution, so I installed it using
rpm -ivh expect-5.43.0-5.1.x86_64.rpm
Expect depends on TCL and optionally on TK, but these were already installed in my VM as part of my default configuration.
This was my first attempt (t3.exp):
#!/usr/bin/expect -f
spawn /u01/app/oracle/product/11.2.0/dbhome_1/OPatch/ocm/bin/emocmrsp \
-no_banner -output /home/oracle/expect/ocm3.rsp
expect {
  "Email address/User Name:"
    send "\n"
  "Do you wish to remain uninformed of security issues*"
    send "Y\n"
Expect is similar to a shell scripting language so a directive can be included in the first line to use /usr/bin/expect as shown above. In this case the -f flag indicates that the remainder of the file is the expect script.
The first action is to execute emocmrsp using the spawn directive. The rest of the script consists of an expect command. When emocmrsp prints the line “Email address/User Name:” expect will respond with a newline character. When emocmrsp prints the security issues question, expect will respond with a Y followed by a newline character.

Niciun comentariu:

Trimiteți un comentariu