Home | History | Annotate | Download | only in doc
      1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      2 <html>
      3 <head>
      4 <title>Pexpect - Examples</title>
      5 <link rel="stylesheet" href="clean.css" type="text/css">
      6 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      7 <meta name="Author" content="Noah Spurrier">
      8 <meta name="Keywords"
      9  content="pexpect, Noah Spurrier, Python, Libes, TCL, Expect, pipe, popen, pyExpect, expectpy, expect-like, expect-alike, expect like">
     10 <meta name="Description" content="Examples for using Pexpect.">
     11 </head>
     12 <body bgcolor="#ffffff" text="#000000">
     13 <div id="Header">
     14 <h1>Pexpect Examples</h1>
     15 </div>
     16 <div id="Content">
     17 
     18 <p><span class="code">hive.py</span></p>
     19 <p><blockquote>
     20 This script creates SSH connections to a list of hosts that
     21 you provide. Then you are given a command line prompt. Each
     22 shell command that you enter is sent to all the hosts. The
     23 response from each host is collected and printed. For example,
     24 you could connect to a dozen different machines and reboot
     25 them all at once.
     26 </p></blockquote>
     27 
     28 <p><span class="code">script.py</span></p>
     29 <p><blockquote>
     30  This implements a command similar to the classic BSD
     31 "script" command.
     32  This will start a subshell and log all input and
     33 output to a file.
     34  This demonstrates the interact() method of Pexpect.
     35 </p></blockquote>
     36 
     37 <p><span class="code">fix_cvs_files.py</span></p>
     38 <p><blockquote>
     39  This is for cleaning up binary files improperly
     40 added to CVS.
     41  This script scans the given path to find binary
     42 files;
     43  checks with CVS to see if the sticky options are set
     44 to -kb;
     45  finally if sticky options are not -kb then uses 'cvs
     46 admin' to
     47  set the -kb option.
     48 </p></blockquote>
     49 
     50 <p><span class="code">ftp.py</span></p>
     51 <p><blockquote>
     52  This demonstrates an FTP "bookmark".
     53  This connects to an ftp site; does a few ftp stuff;
     54 and then gives the user
     55  interactive control over the session. In this case
     56 the "bookmark" is to a
     57  directory on the OpenBSD ftp server. It puts you in
     58 the i386 packages
     59  directory. You can easily modify this for other
     60 sites.
     61  This demonstrates the interact() method of Pexpect.
     62 </p></blockquote>
     63 
     64 <p><span class="code">monitor.py</span></p>
     65 <p><blockquote>
     66  This runs a sequence of commands on a remote host
     67 using SSH.
     68  It runs a simple system checks such as uptime and
     69 free to monitor
     70  the state of the remote host.
     71 </p></blockquote>
     72 
     73 <p><span class="code">passmass.py</span></p>
     74 <p><blockquote>
     75  This will login to each given server and change the
     76 password of the
     77  given user. This demonstrates scripting logins and
     78 passwords.
     79 </p></blockquote>
     80 
     81 <p><span class="code">python.py</span></p>
     82 <p><blockquote>
     83  This starts the python interpreter and prints the
     84 greeting message backwards.
     85  It then gives the user iteractive control of Python.
     86 It's pretty useless!
     87 </p></blockquote>
     88 
     89 <p><span class="code">rippy.py</span></p>
     90 <p><blockquote>
     91  This is a wizard for mencoder. It greatly simplifies
     92 the process of
     93  ripping a DVD to Divx (mpeg4) format. It can
     94 transcode from any
     95  video file to another. It has options for resampling
     96 the audio stream;
     97  removing interlace artifacts, fitting to a target
     98 file size, etc.
     99  There are lots of options, but the process is simple
    100 and easy to use.
    101 </p></blockquote>
    102 
    103 <p><span class="code">sshls.py</span></p>
    104 <p><blockquote>
    105  This lists a directory on a remote machine.
    106 </p></blockquote>
    107 <p><span class="code">ssh_tunnel.py</span></p>
    108 <p><blockquote>
    109  This starts an SSH tunnel to a remote machine. It
    110 monitors the connection
    111  and restarts the tunnel if it goes down.
    112 </p></blockquote>
    113 <p><span class="code">uptime.py</span></p>
    114 <p><blockquote>
    115  This will run the uptime command and parse the
    116 output into variables.
    117  This demonstrates using a single regular expression
    118 to match the output
    119  of a command and capturing different variable in
    120 match groups.
    121  The grouping regular expression handles a wide variety of different
    122 uptime formats.
    123   </blockquote>
    124 
    125 <p>
    126 <a href="http://sourceforge.net/projects/pexpect/"
    127  title="The Pexpect project page on SourceForge.net"> <img
    128  src="http://sourceforge.net/sflogo.php?group_id=59762&type=5"
    129  alt="The Pexpect project page on SourceForge.net" border="0"
    130  height="31" width="105"> </a>
    131 </p>
    132 </div>
    133 
    134 </body>
    135 </html>
    136