Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Side by Side Diff: third_party/pexpect/examples/astat.py

Issue 1398903002: Add third_party/pexpect (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@end-to-end-test
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/pexpect/examples/README ('k') | third_party/pexpect/examples/cgishell.cgi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 '''This runs Apache Status on the remote host and returns the number of requests per second.
4
5 ./astat.py [-s server_hostname] [-u username] [-p password]
6 -s : hostname of the remote server to login to.
7 -u : username to user for login.
8 -p : Password to user for login.
9
10 Example:
11 This will print information about the given host:
12 ./astat.py -s www.example.com -u mylogin -p mypassword
13
14 PEXPECT LICENSE
15
16 This license is approved by the OSI and FSF as GPL-compatible.
17 http://opensource.org/licenses/isc-license.txt
18
19 Copyright (c) 2012, Noah Spurrier <noah@noah.org>
20 PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
21 PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
22 COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
23 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
24 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
25 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
26 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
27 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
28 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
29 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30
31 '''
32
33 from __future__ import print_function
34
35 from __future__ import absolute_import
36
37 import os
38 import sys
39 import getopt
40 import getpass
41 import pxssh
42
43
44 try:
45 raw_input
46 except NameError:
47 raw_input = input
48
49
50 def exit_with_usage():
51
52 print(globals()['__doc__'])
53 os._exit(1)
54
55
56 def main():
57
58 ######################################################################
59 ## Parse the options, arguments, get ready, etc.
60 ######################################################################
61 try:
62 optlist, args = getopt.getopt(sys.argv[1:], 'h?s:u:p:', ['help','h','?'] )
63 except Exception as e:
64 print(str(e))
65 exit_with_usage()
66 options = dict(optlist)
67 if len(args) > 1:
68 exit_with_usage()
69
70 if [elem for elem in options if elem in ['-h','--h','-?','--?','--help']]:
71 print("Help:")
72 exit_with_usage()
73
74 if '-s' in options:
75 hostname = options['-s']
76 else:
77 hostname = raw_input('hostname: ')
78 if '-u' in options:
79 username = options['-u']
80 else:
81 username = raw_input('username: ')
82 if '-p' in options:
83 password = options['-p']
84 else:
85 password = getpass.getpass('password: ')
86
87 #
88 # Login via SSH
89 #
90 p = pxssh.pxssh()
91 p.login(hostname, username, password)
92 p.sendline('apachectl status')
93 p.expect('([0-9]+\.[0-9]+)\s*requests/sec')
94 requests_per_second = p.match.groups()[0]
95 p.logout()
96 print(requests_per_second)
97
98 if __name__ == "__main__":
99 main()
OLDNEW
« no previous file with comments | « third_party/pexpect/examples/README ('k') | third_party/pexpect/examples/cgishell.cgi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698