1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
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">
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.">
12 <body bgcolor="#ffffff" text="#000000">
14 <h1>Pexpect Examples</h1>
18 <p><span class="code">hive.py</span></p>
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
28 <p><span class="code">script.py</span></p>
30 This implements a command similar to the classic BSD
32 This will start a subshell and log all input and
34 This demonstrates the interact() method of Pexpect.
37 <p><span class="code">fix_cvs_files.py</span></p>
39 This is for cleaning up binary files improperly
41 This script scans the given path to find binary
43 checks with CVS to see if the sticky options are set
45 finally if sticky options are not -kb then uses 'cvs
50 <p><span class="code">ftp.py</span></p>
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
59 directory. You can easily modify this for other
61 This demonstrates the interact() method of Pexpect.
64 <p><span class="code">monitor.py</span></p>
66 This runs a sequence of commands on a remote host
68 It runs a simple system checks such as uptime and
70 the state of the remote host.
73 <p><span class="code">passmass.py</span></p>
75 This will login to each given server and change the
77 given user. This demonstrates scripting logins and
81 <p><span class="code">python.py</span></p>
83 This starts the python interpreter and prints the
84 greeting message backwards.
85 It then gives the user iteractive control of Python.
89 <p><span class="code">rippy.py</span></p>
91 This is a wizard for mencoder. It greatly simplifies
93 ripping a DVD to Divx (mpeg4) format. It can
95 video file to another. It has options for resampling
97 removing interlace artifacts, fitting to a target
99 There are lots of options, but the process is simple
103 <p><span class="code">sshls.py</span></p>
105 This lists a directory on a remote machine.
107 <p><span class="code">ssh_tunnel.py</span></p>
109 This starts an SSH tunnel to a remote machine. It
110 monitors the connection
111 and restarts the tunnel if it goes down.
113 <p><span class="code">uptime.py</span></p>
115 This will run the uptime command and parse the
116 output into variables.
117 This demonstrates using a single regular expression
119 of a command and capturing different variable in
121 The grouping regular expression handles a wide variety of different
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>