WebTech Varna 2007 Expect – the unexpected Marian Marinov – System Architect - Siteground.com.

Slides:



Advertisements
Similar presentations
Social Web Design 1 Darby Chang Social Web Design.
Advertisements

Molecular Biomedical Informatics Web Programming 1.
1 Input/Output and Debugging  How to use IO Streams  How to debug programs.
LINUX System : Lecture 3 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement.
FILE TRANSFER PROTOCOL Short for File Transfer Protocol, the protocol for exchanging files over the Internet. FTP works in the same way as HTTP for transferring.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
Scripting Languages and C-Shell. What is a scripting language ? Script is a sequence of commands written as plain text and run by an interpreter (shell).
Scripting Languages CS351 – Programming Paradigms.
Scripting Languages. Originally, a script was a file containing a sequence of commands that needed to be executed Control structures were added to make.
Unix Shell Scripts. What are scripts ? Text files in certain format that are run by another program Examples: –Perl –Javascript –Shell scripts (we learn.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
Help session: Unix basics Keith 9/9/2011. Login in Unix lab  User name: ug0xx Password: ece321 (initial)  The password will not be displayed on the.
Chapter 5 Bourne Shells Scripts By C. Shing ITEC Dept Radford University.
Unix Talk #2 (sed). 2 You have learned…  Regular expressions, grep, & egrep  grep & egrep are tools used to search for text in a file  AWK -- powerful.
An Introduction to Unix Shell Scripting
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
C Basic File Input/Output Manipulation C Programming – File Outline v File handling in C - opening and closing. v Reading from and writing to files.
CGI Security COEN 351. CGI Security Security holes are exploited by user input. We need to check user input against Buffer overflows etc. that cause a.
FTP Server and FTP Commands By Nanda Ganesan, Ph.D. © Nanda Ganesan, All Rights Reserved.
CS 403: Programming Languages Fall 2004 Department of Computer Science University of Alabama Joel Jones.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
File Handling Spring 2013Programming and Data Structure1.
Before we start…Getting Started. UST Outline History Getting Started Basic commands (command line) Operations on Files and Directories Input and Output.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
Tool for Automation and Testing
File IO and command line input CSE 2451 Rong Shi.
Cygwin Training Seminar January 27, 2005 MDL AWIPS (Room 10246)
Introduction to Unix – CS 21
Storing and Retrieving Data
20-753: Fundamentals of Web Programming 1 Lecture 10: Server-Side Scripting II Fundamentals of Web Programming Lecture 10: Server-Side Scripting II.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Files & Directories.
40 Years and Still Rocking the Terminal!
Chapter 7 Files By C. Shing ITEC Dept Radford University.
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
GAME203 – C Files stdio.h C standard Input/Output “getchar()”
FTP COMMANDS OBJECTIVES. General overview. Introduction to FTP server. Types of FTP users. FTP commands examples. FTP commands in action (example of use).
File Transfer Protocol (FTP) CIS 130. File Transfer Protocol (FTP) Copy files from one internet host (server) to your account on another host –Need domain.
Review Please turn in your homework and practicals Packages, installation, rpm command Apache – Quick and easy way to set up a web server to play around.
Files A collection of related data treated as a unit. Two types Text
Agenda The Bourne Shell – Part I Redirection ( >, >>,
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Perl Subroutines User Input Perl on linux Forks and Pipes.
Hank Childs, University of Oregon April 15 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
CIRC Summer School 2016 Baowei Liu
Software Testing Techniques
CIRC Summer School 2017 Baowei Liu
CIRC Winter Boot Camp 2017 Baowei Liu
FTP Lecture supp.
Sydney Opera House.
Unix Scripting Session 4 March 27, 2008.
CSE 303 Concepts and Tools for Software Development
Tutorial of Unix Command & shell scriptS 5027
CS111 Computer Programming
File Input/Output.
FTP and UNIX TOPICS Exploring your Web Hosting Site FTP UNIX
Programming in C Input / Output.
Programming in C Input / Output.
Hank Childs, University of Oregon
File I/O We are used to reading from and writing to the terminal:
CSC 352– Unix Programming, Spring 2016
Unix Talk #2 (sed).
File Input and Output.
Programming in C Input / Output.
Files.
Chapter 5 Bourne Shells Scripts
File I/O.
File I/O We are used to reading from and writing to the terminal:
Presentation transcript:

WebTech Varna 2007 Expect – the unexpected Marian Marinov – System Architect - Siteground.com

2 Agenda ➢ What is Expect and where it can help ➢ Implementations ➢ UNIX tool expect ➢ Python pexpect ➢ Perl Expect ➢ PHP expect Marian Marinov - Varna /30

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 Marian Marinov - Varna /30

4 UNIX Expect application Requirements:tcl & expect Don Libes - expect expect1.1> send "hello world" hello worldexpect1.2> exit expect expect1.1> send "hello world\n"; hello world expect1.2> exit Marian Marinov - Varna /30

5 UNIX Expect application cat speak.exp #!./expect -f send "hello world\n" hello world Marian Marinov - Varna /30

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 Marian Marinov - Varna /30

7 UNIX Expect application match_max 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 Marian Marinov - Varna /30

8 UNIX Expect application expect { # nestead expectes -re "" { } -exact "" { } -re "" { } Marian Marinov - Varna /30

9 UNIX Expect application Get some user input: stty -echo expect_user -re "(.*)\n" set password $expect_out(1,string) send_user "\n" Marian Marinov - Varna /30

10 UNIX Expect application Show some examples :) Marian Marinov - Varna /30

11 UNIX Expect application I'm stupid and I didn't understood anything Can I still use Expect? YES autoexpect Marian Marinov - Varna /30

12 UNIX Expect application autoexpect ftp ftp.example.com autoexpect -f ftp.exp ftp ftp.example.com -c – conservative mode -p – prompt mode Marian Marinov - Varna /30

13 Python pexpect package URL: Requirements: python2.4 & pty package Installation: 1. download pexpect-2.1.tar.gz 2. tar zxf pexpect-2.1.tar.gz 3. cd pexpect python setup.py install Marian Marinov - Varna /30

14 Python pexpect package import pexpect child = pexpect.spawn ('ftp ftp.openbsd.org') child.expect ('Name.*: ') child.sendline ('anonymous') child.expect ('Password:') child.sendline child.expect ('ftp> ') child.sendline ('cd pub') child.expect('ftp> ') child.sendline ('get ls-lR.gz') child.expect('ftp> ') child.sendline ('bye') Marian Marinov - Varna /30

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+\r\n') - 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 Marian Marinov - Varna /30

16 Expect for Perl Packages: Expect Expect::Simple Installation: perl -MCPAN -e 'install Expect' perl -MCPAN -e 'install Expect::Simple' Download and compile ( Marian Marinov - Varna /30

17 Expect for Perl Expect->new(); $object->debug($debug_level); $object->exp_internal(0 | 1); $object->raw_pty(0 | 1); Marian Marinov - Varna /30

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); Marian Marinov - Varna /30

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); Marian Marinov - Varna /30

20 Expect in PHP Requirements: libexpect >= PHP >= PECL Installation: pear install expect Marian Marinov - Varna /30

21 Expect in PHP ini_set ("expect.loguser", "Off"); $stream = fopen ("expect://ssh uptime", "r"); $cases = array ( array (0 => "password:", 1 => PASSWORD) ); Marian Marinov - Varna /30

22 Expect in PHP switch (expect_expectl ($stream, $cases)) { case PASSWORD: fwrite ($stream, "password\n"); break; default: die ("Error was occurred while connecting to the remote host!\n"); } while ($line = fgets ($stream)) { print $line; } fclose ($stream); Marian Marinov - Varna /30