3 """This runs Apache Status on the remote host and returns the number of requests per second.
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.
11 This will print information about the given host:
12 ./astat.py -s www.example.com -u mylogin -p mypassword
16 import os, sys, time, re, getopt, getpass
20 def exit_with_usage():
22 print globals()['__doc__']
27 ######################################################################
28 ## Parse the options, arguments, get ready, etc.
29 ######################################################################
31 optlist, args = getopt.getopt(sys.argv[1:], 'h?s:u:p:', ['help','h','?'])
35 options = dict(optlist)
39 if [elem for elem in options if elem in ['-h','--h','-?','--?','--help']]:
44 hostname = options['-s']
46 hostname = raw_input('hostname: ')
48 username = options['-u']
50 username = raw_input('username: ')
52 password = options['-p']
54 password = getpass.getpass('password: ')
60 p.login(hostname, username, password)
61 p.sendline('apachectl status')
62 p.expect('([0-9]+\.[0-9]+)\s*requests/sec')
63 requests_per_second = p.match.groups()[0]
65 print requests_per_second
67 if __name__ == "__main__":