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>
20This script creates SSH connections to a list of hosts that
21you provide. Then you are given a command line prompt. Each
22shell command that you enter is sent to all the hosts. The
23response from each host is collected and printed. For example,
24you could connect to a dozen different machines and reboot
25them 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
33output 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
40added to CVS.
41 This script scans the given path to find binary
42files;
43 checks with CVS to see if the sticky options are set
44to -kb;
45 finally if sticky options are not -kb then uses 'cvs
46admin' 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;
54and then gives the user
55 interactive control over the session. In this case
56the "bookmark" is to a
57 directory on the OpenBSD ftp server. It puts you in
58the i386 packages
59 directory. You can easily modify this for other
60sites.
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
67using SSH.
68 It runs a simple system checks such as uptime and
69free 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
76password of the
77 given user. This demonstrates scripting logins and
78passwords.
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
84greeting message backwards.
85 It then gives the user iteractive control of Python.
86It'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
92the process of
93 ripping a DVD to Divx (mpeg4) format. It can
94transcode from any
95 video file to another. It has options for resampling
96the audio stream;
97 removing interlace artifacts, fitting to a target
98file size, etc.
99 There are lots of options, but the process is simple
100and 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
110monitors 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
116output into variables.
117 This demonstrates using a single regular expression
118to match the output
119 of a command and capturing different variable in
120match groups.
121 The grouping regular expression handles a wide variety of different
122uptime 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