forked from OSchip/llvm-project
136 lines
4.1 KiB
HTML
136 lines
4.1 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<title>Pexpect - Examples</title>
|
|
<link rel="stylesheet" href="clean.css" type="text/css">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<meta name="Author" content="Noah Spurrier">
|
|
<meta name="Keywords"
|
|
content="pexpect, Noah Spurrier, Python, Libes, TCL, Expect, pipe, popen, pyExpect, expectpy, expect-like, expect-alike, expect like">
|
|
<meta name="Description" content="Examples for using Pexpect.">
|
|
</head>
|
|
<body bgcolor="#ffffff" text="#000000">
|
|
<div id="Header">
|
|
<h1>Pexpect Examples</h1>
|
|
</div>
|
|
<div id="Content">
|
|
|
|
<p><span class="code">hive.py</span></p>
|
|
<p><blockquote>
|
|
This script creates SSH connections to a list of hosts that
|
|
you provide. Then you are given a command line prompt. Each
|
|
shell command that you enter is sent to all the hosts. The
|
|
response from each host is collected and printed. For example,
|
|
you could connect to a dozen different machines and reboot
|
|
them all at once.
|
|
</p></blockquote>
|
|
|
|
<p><span class="code">script.py</span></p>
|
|
<p><blockquote>
|
|
This implements a command similar to the classic BSD
|
|
"script" command.
|
|
This will start a subshell and log all input and
|
|
output to a file.
|
|
This demonstrates the interact() method of Pexpect.
|
|
</p></blockquote>
|
|
|
|
<p><span class="code">fix_cvs_files.py</span></p>
|
|
<p><blockquote>
|
|
This is for cleaning up binary files improperly
|
|
added to CVS.
|
|
This script scans the given path to find binary
|
|
files;
|
|
checks with CVS to see if the sticky options are set
|
|
to -kb;
|
|
finally if sticky options are not -kb then uses 'cvs
|
|
admin' to
|
|
set the -kb option.
|
|
</p></blockquote>
|
|
|
|
<p><span class="code">ftp.py</span></p>
|
|
<p><blockquote>
|
|
This demonstrates an FTP "bookmark".
|
|
This connects to an ftp site; does a few ftp stuff;
|
|
and then gives the user
|
|
interactive control over the session. In this case
|
|
the "bookmark" is to a
|
|
directory on the OpenBSD ftp server. It puts you in
|
|
the i386 packages
|
|
directory. You can easily modify this for other
|
|
sites.
|
|
This demonstrates the interact() method of Pexpect.
|
|
</p></blockquote>
|
|
|
|
<p><span class="code">monitor.py</span></p>
|
|
<p><blockquote>
|
|
This runs a sequence of commands on a remote host
|
|
using SSH.
|
|
It runs a simple system checks such as uptime and
|
|
free to monitor
|
|
the state of the remote host.
|
|
</p></blockquote>
|
|
|
|
<p><span class="code">passmass.py</span></p>
|
|
<p><blockquote>
|
|
This will login to each given server and change the
|
|
password of the
|
|
given user. This demonstrates scripting logins and
|
|
passwords.
|
|
</p></blockquote>
|
|
|
|
<p><span class="code">python.py</span></p>
|
|
<p><blockquote>
|
|
This starts the python interpreter and prints the
|
|
greeting message backwards.
|
|
It then gives the user iteractive control of Python.
|
|
It's pretty useless!
|
|
</p></blockquote>
|
|
|
|
<p><span class="code">rippy.py</span></p>
|
|
<p><blockquote>
|
|
This is a wizard for mencoder. It greatly simplifies
|
|
the process of
|
|
ripping a DVD to Divx (mpeg4) format. It can
|
|
transcode from any
|
|
video file to another. It has options for resampling
|
|
the audio stream;
|
|
removing interlace artifacts, fitting to a target
|
|
file size, etc.
|
|
There are lots of options, but the process is simple
|
|
and easy to use.
|
|
</p></blockquote>
|
|
|
|
<p><span class="code">sshls.py</span></p>
|
|
<p><blockquote>
|
|
This lists a directory on a remote machine.
|
|
</p></blockquote>
|
|
<p><span class="code">ssh_tunnel.py</span></p>
|
|
<p><blockquote>
|
|
This starts an SSH tunnel to a remote machine. It
|
|
monitors the connection
|
|
and restarts the tunnel if it goes down.
|
|
</p></blockquote>
|
|
<p><span class="code">uptime.py</span></p>
|
|
<p><blockquote>
|
|
This will run the uptime command and parse the
|
|
output into variables.
|
|
This demonstrates using a single regular expression
|
|
to match the output
|
|
of a command and capturing different variable in
|
|
match groups.
|
|
The grouping regular expression handles a wide variety of different
|
|
uptime formats.
|
|
</blockquote>
|
|
|
|
<p>
|
|
<a href="http://sourceforge.net/projects/pexpect/"
|
|
title="The Pexpect project page on SourceForge.net"> <img
|
|
src="http://sourceforge.net/sflogo.php?group_id=59762&type=5"
|
|
alt="The Pexpect project page on SourceForge.net" border="0"
|
|
height="31" width="105"> </a>
|
|
</p>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|