18a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny ChenThis directory contains scripts that give examples of using Pexpect. 28a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 38a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chenhive.py 48a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This script creates SSH connections to a list of hosts that 58a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen you provide. Then you are given a command line prompt. Each 68a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen shell command that you enter is sent to all the hosts. The 78a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen response from each host is collected and printed. For example, 88a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen you could connect to a dozen different machines and reboot 98a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen them all at once. 108a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 118a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chenscript.py 128a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This implements a command similar to the classic BSD "script" command. 138a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This will start a subshell and log all input and output to a file. 148a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This demonstrates the interact() method of Pexpect. 158a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 168a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chenfix_cvs_files.py 178a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This is for cleaning up binary files improperly added to 188a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen CVS. This script scans the given path to find binary files; 198a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen checks with CVS to see if the sticky options are set to -kb; 208a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen finally if sticky options are not -kb then uses 'cvs admin' 218a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen to set the -kb option. 228a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 238a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chenftp.py 248a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This demonstrates an FTP "bookmark". 258a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This connects to an ftp site; does a few ftp commands; and then gives the user 268a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen interactive control over the session. In this case the "bookmark" is to a 278a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen directory on the OpenBSD ftp server. It puts you in the i386 packages 288a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen directory. You can easily modify this for other sites. 298a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This demonstrates the interact() method of Pexpect. 308a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 318a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chenmonitor.py 328a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This runs a sequence of system status commands on a remote host using SSH. 338a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen It runs a simple system checks such as uptime and free to monitor 348a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen the state of the remote host. 358a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 368a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chenpassmass.py 378a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This will login to a list of hosts and change the password of the 388a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen given user. This demonstrates scripting logins; although, you could 398a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen more easily do this using the pxssh subclass of Pexpect. 408a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen See also the "hive.py" example script for a more general example 418a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen of scripting a collection of servers. 428a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 438a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chenpython.py 448a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This starts the python interpreter and prints the greeting message backwards. 458a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen It then gives the user interactive control of Python. It's pretty useless! 468a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 478a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chenrippy.py 488a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This is a wizard for mencoder. It greatly simplifies the process of 498a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen ripping a DVD to mpeg4 format (XviD, DivX). It can transcode from any 508a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen video file to another. It has options for resampling the audio stream; 518a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen removing interlace artifacts, fitting to a target file size, etc. 528a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen There are lots of options, but the process is simple and easy to use. 538a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 548a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chensshls.py 558a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This lists a directory on a remote machine. 568a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 578a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chenssh_tunnel.py 588a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This starts an SSH tunnel to a remote machine. It monitors the connection 598a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen and restarts the tunnel if it goes down. 608a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 618a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chenuptime.py 628a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This will run the uptime command and parse the output into python variables. 638a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This demonstrates using a single regular expression to match the output 648a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen of a command and capturing different variable in match groups. 658a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen The regular expression takes into account a wide variety of different 668a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen formats for uptime output. 678a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 688a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chendf.py 698a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen This collects filesystem capacity info using the 'df' command. 708a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen Tuples of filesystem name and percentage are stored in a list. 718a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen A simple report is printed. Filesystems over 95% capacity are highlighted. 728a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen 73