SlideShare a Scribd company logo
1 of 22
WebTech Varna 2007

Expect – the unexpected


 Marian Marinov – mm@yuhu.biz
System Architect - Siteground.com
Agenda



            ➢ What is Expect and      where it can help
            ➢ Implementations
                            `
              ➢ UNIX tool expect
              ➢ Python pexpect
              ➢ Perl Expect
              ➢ PHP expect



                                                          2

Marian Marinov - mm@yuhu.biz   1/30         WebTech Varna 2007
What is Expect


          ➢ Automating Interactive Applications
          ➢ Unique System Administrators tool
          ➢ Just Another TCL extension
          ➢ Great automated application tester

          Where to use it:
          ➢ passwd automations
          ➢ automation of ncurses based application
          ➢ automated patch management

                                                      3

Marian Marinov - mm@yuhu.biz   2/30     WebTech Varna 2007
UNIX Expect application

            Requirements: tcl & expect
            Don Libes - http://expect.nist.gov/

            hackman@gamelon:~$ expect
            expect1.1> send "hello world"
            hello worldexpect1.2> exit

            hackman@gamelon:~$ expect
            expect1.1> send "hello worldn";
            hello world
            expect1.2> exit
                                                       4

Marian Marinov - mm@yuhu.biz   3/30      WebTech Varna 2007
UNIX Expect application


            hackman@gamelon:~$ cat speak.exp
            #!./expect -f
            send "hello worldn"

            hackman@gamelon:~$ ./speak.exp
            hello world



                                                    5

Marian Marinov - mm@yuhu.biz   4/30   WebTech Varna 2007
UNIX Expect application


            send – sending string to the command
            send_user – sending string to STDOUT
            send_log – sending string to text log file
            set timeout -1|0|60 – maximum wait for
              command input
            stty -echo – turn off KBD echo
            spawn – start a program
            interact – returns the control of the
              started command back to user

                                                         6

Marian Marinov - mm@yuhu.biz   5/30       WebTech Varna 2007
UNIX Expect application


            match_max 100000 - max buffer size
            log_user 0|1 – enable/disable logging to
              STDOUT
            log_file filename – file where to store the
              script output as addition to STDOUT
            expect -exact – match exact string
            expect -re – match regular expression
            expect eof – wait the command to finish

                                                        7

Marian Marinov - mm@yuhu.biz   6/30       WebTech Varna 2007
UNIX Expect application


            expect {
                # nestead expectes
                -re "" {
                }
                -exact "" {
                }
                -re "" {
                }
            }

                                                    8

Marian Marinov - mm@yuhu.biz   7/30   WebTech Varna 2007
UNIX Expect application


            Get some user input:

                  stty -echo
                  expect_user -re "(.*)n"
                  set password $expect_out(1,string)
                  send_user "n"



                                                       9

Marian Marinov - mm@yuhu.biz   8/30      WebTech Varna 2007
UNIX Expect application




            Show some examples :)




                                                    10

Marian Marinov - mm@yuhu.biz   9/30   WebTech Varna 2007
UNIX Expect application


                  I'm stupid and
          I didn't understood anything

                 Can I still use Expect?

                               YES

                        autoexpect

                                                         11

Marian Marinov - mm@yuhu.biz     10/30     WebTech Varna 2007
UNIX Expect application



          autoexpect ftp ftp.example.com

          autoexpect -f ftp.exp ftp ftp.example.com

          -c – conservative mode
          -p – prompt mode



                                                           12

Marian Marinov - mm@yuhu.biz    11/30        WebTech Varna 2007
Python pexpect package


          URL: http://pexpect.sourceforge.net/

          Requirements: python2.4 & pty package

          Installation:
             1. download pexpect-2.1.tar.gz
             2. tar zxf pexpect-2.1.tar.gz
             3. cd pexpect-2.1
             4. python setup.py install


                                                            13

Marian Marinov - mm@yuhu.biz   12/30          WebTech Varna 2007
Python pexpect package

          import pexpect
          child = pexpect.spawn ('ftp ftp.openbsd.org')
          child.expect ('Name .*: ')
          child.sendline ('anonymous')
          child.expect ('Password:')
          child.sendline ('test@example.com')
          child.expect ('ftp> ')
          child.sendline ('cd pub')
          child.expect('ftp> ')
          child.sendline ('get ls-lR.gz')
          child.expect('ftp> ')
          child.sendline ('bye')
                                                           14

Marian Marinov - mm@yuhu.biz    13/30        WebTech Varna 2007
Python pexpect package

          Regular expression problems:

          matching the end of the line can be tricky :)
          The $ pattern for end of line match is useless.

          child.expect ('w+rn') - matching word at the end
       of the line

          minimal match(instead of the standard greedy):

          child.expect ('.+') - match always one char
          child.expect ('.*') - match always zero or one char
                                                            15

Marian Marinov - mm@yuhu.biz     14/30        WebTech Varna 2007
Expect for Perl


            Packages:
                Expect
                Expect::Simple

            Installation:
                 perl -MCPAN -e 'install Expect'
                 perl -MCPAN -e 'install Expect::Simple'
                 Download and compile
                     (http://search.cpan.org)


                                                           16

Marian Marinov - mm@yuhu.biz    15/30       WebTech Varna 2007
Expect for Perl



        Expect->new();
        $object->spawn(@command);
        $object->debug($debug_level);
        $object->exp_internal(0 | 1);
        $object->raw_pty(0 | 1);




                                                      17

Marian Marinov - mm@yuhu.biz   16/30    WebTech Varna 2007
Expect for Perl


        $object->match();
        $object->matchlist();
        $object->match_number();
        $object->error();
        $object->command();
        $object->exitstatus();
        $object->do_soft_close();
        $object->restart_timeout_upon_receive(0 | 1);


                                                         18

Marian Marinov - mm@yuhu.biz   17/30       WebTech Varna 2007
Expect for Perl



        $object->log_group(0 | 1 | undef);
        $object->log_user(0 | 1 | undef);
        $object->log_file("filename" | $filehandle | &coderef |
          undef);
        $object->match_max($max_buffersize or undef);
        $object->pid();
        $object->send_slow($string_to_send);
        $object->send_slow($delay, @strings_to_send);


                                                            19

Marian Marinov - mm@yuhu.biz     18/30        WebTech Varna 2007
Expect in PHP


            Requirements:
                libexpect >= 5.43.0
                PHP >= 4.3.0
                PECL

            Installation:
                 pear install expect




                                                      20

Marian Marinov - mm@yuhu.biz    19/30   WebTech Varna 2007
Expect in PHP



             ini_set ("expect.loguser", "Off");
             $stream = fopen ("expect://ssh root@remotehost
                uptime", "r");
             $cases = array (
               array (0 => "password:", 1 => PASSWORD)
             );



                                                         21

Marian Marinov - mm@yuhu.biz   20/30       WebTech Varna 2007
Expect in PHP

             switch (expect_expectl ($stream, $cases)) {
              case PASSWORD:
               fwrite ($stream, "passwordn");
               break;
              default:
               die ("Error was occurred while connecting to the
               remote host!n");
             }
             while ($line = fgets ($stream)) {
               print $line;
             }
             fclose ($stream);
                                                           22

Marian Marinov - mm@yuhu.biz    21/30        WebTech Varna 2007

More Related Content

Similar to Expect the unexpected

OSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ InfosectrainOSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ InfosectrainInfosecTrain
 
Installation of lammps-5Nov14 on Mac OS X Yosemite
Installation of lammps-5Nov14 on Mac OS X YosemiteInstallation of lammps-5Nov14 on Mac OS X Yosemite
Installation of lammps-5Nov14 on Mac OS X Yosemitefirst name chibaf
 
Great Hiroshima with Python 170830
Great Hiroshima with Python 170830Great Hiroshima with Python 170830
Great Hiroshima with Python 170830Takuya Nishimoto
 
SFSCON23 - Carlos Esteban Budde - Predict security attacks in FOSS
SFSCON23 - Carlos Esteban Budde - Predict security attacks in FOSSSFSCON23 - Carlos Esteban Budde - Predict security attacks in FOSS
SFSCON23 - Carlos Esteban Budde - Predict security attacks in FOSSSouth Tyrol Free Software Conference
 
Cansec West 2009
Cansec West 2009Cansec West 2009
Cansec West 2009abhicc285
 
TDC2016POA | Trilha Infraestrutura - Apache Mesos & Marathon: gerenciando rem...
TDC2016POA | Trilha Infraestrutura - Apache Mesos & Marathon: gerenciando rem...TDC2016POA | Trilha Infraestrutura - Apache Mesos & Marathon: gerenciando rem...
TDC2016POA | Trilha Infraestrutura - Apache Mesos & Marathon: gerenciando rem...tdc-globalcode
 
LavaJUG-Maven 3.x, will it lives up to its promises
LavaJUG-Maven 3.x, will it lives up to its promisesLavaJUG-Maven 3.x, will it lives up to its promises
LavaJUG-Maven 3.x, will it lives up to its promisesArnaud Héritier
 
Whitepaper rce cve_2017_9841 | Remote Code Execution Laravel
Whitepaper rce cve_2017_9841 | Remote Code Execution LaravelWhitepaper rce cve_2017_9841 | Remote Code Execution Laravel
Whitepaper rce cve_2017_9841 | Remote Code Execution LaravelChandan Singh Ghodela
 
Performance Profiling in Rust
Performance Profiling in RustPerformance Profiling in Rust
Performance Profiling in RustInfluxData
 
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!Priyanka Aash
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersYury Chemerkin
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - RoutersLogicaltrust pl
 
Navigating the YANGscape of network automation
Navigating the YANGscape of network automationNavigating the YANGscape of network automation
Navigating the YANGscape of network automationRoman Dodin
 
How to install OpenStack MITAKA --allinone - cheat sheet -
How to install OpenStack MITAKA --allinone - cheat sheet -How to install OpenStack MITAKA --allinone - cheat sheet -
How to install OpenStack MITAKA --allinone - cheat sheet -Naoto MATSUMOTO
 
Continuous testing In PHP
Continuous testing In PHPContinuous testing In PHP
Continuous testing In PHPEric Hogue
 
A Distributed Simulation of P-Systems
A Distributed Simulation of P-SystemsA Distributed Simulation of P-Systems
A Distributed Simulation of P-SystemsApostolos Syropoulos
 
Python packaging and dependency resolution
Python packaging and dependency resolutionPython packaging and dependency resolution
Python packaging and dependency resolutionTatiana Al-Chueyr
 

Similar to Expect the unexpected (20)

OSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ InfosectrainOSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ Infosectrain
 
Installation of lammps-5Nov14 on Mac OS X Yosemite
Installation of lammps-5Nov14 on Mac OS X YosemiteInstallation of lammps-5Nov14 on Mac OS X Yosemite
Installation of lammps-5Nov14 on Mac OS X Yosemite
 
Great Hiroshima with Python 170830
Great Hiroshima with Python 170830Great Hiroshima with Python 170830
Great Hiroshima with Python 170830
 
SFSCON23 - Carlos Esteban Budde - Predict security attacks in FOSS
SFSCON23 - Carlos Esteban Budde - Predict security attacks in FOSSSFSCON23 - Carlos Esteban Budde - Predict security attacks in FOSS
SFSCON23 - Carlos Esteban Budde - Predict security attacks in FOSS
 
Cansec West 2009
Cansec West 2009Cansec West 2009
Cansec West 2009
 
Quick and Solid - Baremetal on OpenStack | Rico Lin
Quick and Solid - Baremetal on OpenStack | Rico LinQuick and Solid - Baremetal on OpenStack | Rico Lin
Quick and Solid - Baremetal on OpenStack | Rico Lin
 
MOSP Walkthrough 2009
MOSP Walkthrough 2009MOSP Walkthrough 2009
MOSP Walkthrough 2009
 
TDC2016POA | Trilha Infraestrutura - Apache Mesos & Marathon: gerenciando rem...
TDC2016POA | Trilha Infraestrutura - Apache Mesos & Marathon: gerenciando rem...TDC2016POA | Trilha Infraestrutura - Apache Mesos & Marathon: gerenciando rem...
TDC2016POA | Trilha Infraestrutura - Apache Mesos & Marathon: gerenciando rem...
 
Training open stack networking -neutron
Training open stack networking -neutronTraining open stack networking -neutron
Training open stack networking -neutron
 
LavaJUG-Maven 3.x, will it lives up to its promises
LavaJUG-Maven 3.x, will it lives up to its promisesLavaJUG-Maven 3.x, will it lives up to its promises
LavaJUG-Maven 3.x, will it lives up to its promises
 
Whitepaper rce cve_2017_9841 | Remote Code Execution Laravel
Whitepaper rce cve_2017_9841 | Remote Code Execution LaravelWhitepaper rce cve_2017_9841 | Remote Code Execution Laravel
Whitepaper rce cve_2017_9841 | Remote Code Execution Laravel
 
Performance Profiling in Rust
Performance Profiling in RustPerformance Profiling in Rust
Performance Profiling in Rust
 
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
Breaking Parser Logic: Take Your Path Normalization Off and Pop 0days Out!
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routers
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - Routers
 
Navigating the YANGscape of network automation
Navigating the YANGscape of network automationNavigating the YANGscape of network automation
Navigating the YANGscape of network automation
 
How to install OpenStack MITAKA --allinone - cheat sheet -
How to install OpenStack MITAKA --allinone - cheat sheet -How to install OpenStack MITAKA --allinone - cheat sheet -
How to install OpenStack MITAKA --allinone - cheat sheet -
 
Continuous testing In PHP
Continuous testing In PHPContinuous testing In PHP
Continuous testing In PHP
 
A Distributed Simulation of P-Systems
A Distributed Simulation of P-SystemsA Distributed Simulation of P-Systems
A Distributed Simulation of P-Systems
 
Python packaging and dependency resolution
Python packaging and dependency resolutionPython packaging and dependency resolution
Python packaging and dependency resolution
 

More from Marian Marinov

Dev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingDev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingMarian Marinov
 
Basic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsBasic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsMarian Marinov
 
Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Marian Marinov
 
Introduction and replication to DragonflyDB
Introduction and replication to DragonflyDBIntroduction and replication to DragonflyDB
Introduction and replication to DragonflyDBMarian Marinov
 
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMessage Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMarian Marinov
 
How to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfHow to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfMarian Marinov
 
How to survive in the work from home era
How to survive in the work from home eraHow to survive in the work from home era
How to survive in the work from home eraMarian Marinov
 
Improve your storage with bcachefs
Improve your storage with bcachefsImprove your storage with bcachefs
Improve your storage with bcachefsMarian Marinov
 
Control your service resources with systemd
 Control your service resources with systemd  Control your service resources with systemd
Control your service resources with systemd Marian Marinov
 
Comparison of-foss-distributed-storage
Comparison of-foss-distributed-storageComparison of-foss-distributed-storage
Comparison of-foss-distributed-storageMarian Marinov
 
Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Marian Marinov
 
Securing your MySQL server
Securing your MySQL serverSecuring your MySQL server
Securing your MySQL serverMarian Marinov
 
DoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKDoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKMarian Marinov
 
Challenges with high density networks
Challenges with high density networksChallenges with high density networks
Challenges with high density networksMarian Marinov
 
SiteGround building automation
SiteGround building automationSiteGround building automation
SiteGround building automationMarian Marinov
 
Preventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingPreventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingMarian Marinov
 
Managing a lot of servers
Managing a lot of serversManaging a lot of servers
Managing a lot of serversMarian Marinov
 
Let's Encrypt failures
Let's Encrypt failuresLet's Encrypt failures
Let's Encrypt failuresMarian Marinov
 

More from Marian Marinov (20)

Dev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingDev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & Logging
 
Basic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsBasic presentation of cryptography mechanisms
Basic presentation of cryptography mechanisms
 
Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?
 
Introduction and replication to DragonflyDB
Introduction and replication to DragonflyDBIntroduction and replication to DragonflyDB
Introduction and replication to DragonflyDB
 
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMessage Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
 
How to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfHow to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdf
 
How to survive in the work from home era
How to survive in the work from home eraHow to survive in the work from home era
How to survive in the work from home era
 
Managing sysadmins
Managing sysadminsManaging sysadmins
Managing sysadmins
 
Improve your storage with bcachefs
Improve your storage with bcachefsImprove your storage with bcachefs
Improve your storage with bcachefs
 
Control your service resources with systemd
 Control your service resources with systemd  Control your service resources with systemd
Control your service resources with systemd
 
Comparison of-foss-distributed-storage
Comparison of-foss-distributed-storageComparison of-foss-distributed-storage
Comparison of-foss-distributed-storage
 
Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?
 
Securing your MySQL server
Securing your MySQL serverSecuring your MySQL server
Securing your MySQL server
 
Sysadmin vs. dev ops
Sysadmin vs. dev opsSysadmin vs. dev ops
Sysadmin vs. dev ops
 
DoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKDoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDK
 
Challenges with high density networks
Challenges with high density networksChallenges with high density networks
Challenges with high density networks
 
SiteGround building automation
SiteGround building automationSiteGround building automation
SiteGround building automation
 
Preventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingPreventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel tracking
 
Managing a lot of servers
Managing a lot of serversManaging a lot of servers
Managing a lot of servers
 
Let's Encrypt failures
Let's Encrypt failuresLet's Encrypt failures
Let's Encrypt failures
 

Recently uploaded

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 

Recently uploaded (20)

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 

Expect the unexpected

  • 1. WebTech Varna 2007 Expect – the unexpected Marian Marinov – mm@yuhu.biz System Architect - Siteground.com
  • 2. Agenda ➢ What is Expect and where it can help ➢ Implementations ` ➢ UNIX tool expect ➢ Python pexpect ➢ Perl Expect ➢ PHP expect 2 Marian Marinov - mm@yuhu.biz 1/30 WebTech Varna 2007
  • 3. What is Expect ➢ Automating Interactive Applications ➢ Unique System Administrators tool ➢ Just Another TCL extension ➢ Great automated application tester Where to use it: ➢ passwd automations ➢ automation of ncurses based application ➢ automated patch management 3 Marian Marinov - mm@yuhu.biz 2/30 WebTech Varna 2007
  • 4. UNIX Expect application Requirements: tcl & expect Don Libes - http://expect.nist.gov/ hackman@gamelon:~$ expect expect1.1> send "hello world" hello worldexpect1.2> exit hackman@gamelon:~$ expect expect1.1> send "hello worldn"; hello world expect1.2> exit 4 Marian Marinov - mm@yuhu.biz 3/30 WebTech Varna 2007
  • 5. UNIX Expect application hackman@gamelon:~$ cat speak.exp #!./expect -f send "hello worldn" hackman@gamelon:~$ ./speak.exp hello world 5 Marian Marinov - mm@yuhu.biz 4/30 WebTech Varna 2007
  • 6. UNIX Expect application send – sending string to the command send_user – sending string to STDOUT send_log – sending string to text log file set timeout -1|0|60 – maximum wait for command input stty -echo – turn off KBD echo spawn – start a program interact – returns the control of the started command back to user 6 Marian Marinov - mm@yuhu.biz 5/30 WebTech Varna 2007
  • 7. UNIX Expect application match_max 100000 - max buffer size log_user 0|1 – enable/disable logging to STDOUT log_file filename – file where to store the script output as addition to STDOUT expect -exact – match exact string expect -re – match regular expression expect eof – wait the command to finish 7 Marian Marinov - mm@yuhu.biz 6/30 WebTech Varna 2007
  • 8. UNIX Expect application expect { # nestead expectes -re "" { } -exact "" { } -re "" { } } 8 Marian Marinov - mm@yuhu.biz 7/30 WebTech Varna 2007
  • 9. UNIX Expect application Get some user input: stty -echo expect_user -re "(.*)n" set password $expect_out(1,string) send_user "n" 9 Marian Marinov - mm@yuhu.biz 8/30 WebTech Varna 2007
  • 10. UNIX Expect application Show some examples :) 10 Marian Marinov - mm@yuhu.biz 9/30 WebTech Varna 2007
  • 11. UNIX Expect application I'm stupid and I didn't understood anything Can I still use Expect? YES autoexpect 11 Marian Marinov - mm@yuhu.biz 10/30 WebTech Varna 2007
  • 12. UNIX Expect application autoexpect ftp ftp.example.com autoexpect -f ftp.exp ftp ftp.example.com -c – conservative mode -p – prompt mode 12 Marian Marinov - mm@yuhu.biz 11/30 WebTech Varna 2007
  • 13. Python pexpect package URL: http://pexpect.sourceforge.net/ Requirements: python2.4 & pty package Installation: 1. download pexpect-2.1.tar.gz 2. tar zxf pexpect-2.1.tar.gz 3. cd pexpect-2.1 4. python setup.py install 13 Marian Marinov - mm@yuhu.biz 12/30 WebTech Varna 2007
  • 14. Python pexpect package import pexpect child = pexpect.spawn ('ftp ftp.openbsd.org') child.expect ('Name .*: ') child.sendline ('anonymous') child.expect ('Password:') child.sendline ('test@example.com') child.expect ('ftp> ') child.sendline ('cd pub') child.expect('ftp> ') child.sendline ('get ls-lR.gz') child.expect('ftp> ') child.sendline ('bye') 14 Marian Marinov - mm@yuhu.biz 13/30 WebTech Varna 2007
  • 15. Python pexpect package Regular expression problems: matching the end of the line can be tricky :) The $ pattern for end of line match is useless. child.expect ('w+rn') - matching word at the end of the line minimal match(instead of the standard greedy): child.expect ('.+') - match always one char child.expect ('.*') - match always zero or one char 15 Marian Marinov - mm@yuhu.biz 14/30 WebTech Varna 2007
  • 16. Expect for Perl Packages: Expect Expect::Simple Installation: perl -MCPAN -e 'install Expect' perl -MCPAN -e 'install Expect::Simple' Download and compile (http://search.cpan.org) 16 Marian Marinov - mm@yuhu.biz 15/30 WebTech Varna 2007
  • 17. Expect for Perl Expect->new(); $object->spawn(@command); $object->debug($debug_level); $object->exp_internal(0 | 1); $object->raw_pty(0 | 1); 17 Marian Marinov - mm@yuhu.biz 16/30 WebTech Varna 2007
  • 18. Expect for Perl $object->match(); $object->matchlist(); $object->match_number(); $object->error(); $object->command(); $object->exitstatus(); $object->do_soft_close(); $object->restart_timeout_upon_receive(0 | 1); 18 Marian Marinov - mm@yuhu.biz 17/30 WebTech Varna 2007
  • 19. Expect for Perl $object->log_group(0 | 1 | undef); $object->log_user(0 | 1 | undef); $object->log_file("filename" | $filehandle | &coderef | undef); $object->match_max($max_buffersize or undef); $object->pid(); $object->send_slow($string_to_send); $object->send_slow($delay, @strings_to_send); 19 Marian Marinov - mm@yuhu.biz 18/30 WebTech Varna 2007
  • 20. Expect in PHP Requirements: libexpect >= 5.43.0 PHP >= 4.3.0 PECL Installation: pear install expect 20 Marian Marinov - mm@yuhu.biz 19/30 WebTech Varna 2007
  • 21. Expect in PHP ini_set ("expect.loguser", "Off"); $stream = fopen ("expect://ssh root@remotehost uptime", "r"); $cases = array ( array (0 => "password:", 1 => PASSWORD) ); 21 Marian Marinov - mm@yuhu.biz 20/30 WebTech Varna 2007
  • 22. Expect in PHP switch (expect_expectl ($stream, $cases)) { case PASSWORD: fwrite ($stream, "passwordn"); break; default: die ("Error was occurred while connecting to the remote host!n"); } while ($line = fgets ($stream)) { print $line; } fclose ($stream); 22 Marian Marinov - mm@yuhu.biz 21/30 WebTech Varna 2007