📄 mpdcheck.py
字号:
#!/usr/bin/env python## (C) 2001 by Argonne National Laboratory.# See COPYRIGHT in top-level directory.#"""mpdcheckThis script is a work in progress and may change frequently as we workwith users and gain additional insights into how to improve it.This script prints useful information about the host on which it runs.It is here to help us help users detect problems with configurations oftheir computers. For example, some computers are configured to thinkof themselves simply as 'localhost' with 127.0.0.1 as the IP address.This might present problems if a process on that computer wishes toidentify itself by host and port to a process on another computer.The process on the other computer would try to contact 'localhost'.If you are having problems running parallel jobs via mpd on one or morehosts, you might try running this script once on each of those hosts.Any output with *** at the beginning indicates a potential problemthat you may have to resolve before being able to run parallel jobsvia mpd.For help: mpdcheck -h (or --help) prints this messageIn the following modes, the -v (verbose) option provides info about whatmpdcheck is doing; the -l (long messages) option causes long informationalmessages to print in situations where problems are spotted.The three major modes of operation for this program are: mpdcheck looks for config problems on 'this' host; prints as nec mpdcheck -pc print config info about 'this' host, e.g. contents of /etc/hosts, etc. mpdcheck -f some_file [-ssh] prints info about 'this' host and locatability info about the ones listed in some_file as well (note the file might be mpd.hosts); the -ssh option can be used in conjunction with the -f option to cause ssh tests to be run to each remote host mpdcheck -s runs this program as a server on one host mpdcheck -c server_host server_port runs a client on another (or same) host; connects to the specifed host/port where you previously started the server"""from time import ctime__author__ = "Ralph Butler and Rusty Lusk"__date__ = ctime()__version__ = "$Revision: 1.19 $"__credits__ = ""import refrom sys import argv, exit, stdoutfrom os import path, kill, systemfrom signal import SIGKILLfrom socket import gethostname, getfqdn, gethostbyname_ex, gethostbyaddr, socketfrom popen2 import Popen3from select import select, errorfrom commands import getoutputif __name__ == '__main__': # so I can be imported by pydoc do_ssh = 0 fullDirName = path.abspath(path.split(argv[0])[0]) # normalize hostsFromFile = [] verbose = 0 long_messages = 0 argidx = 1 while argidx < len(argv): if argv[argidx] == '-h' or argv[argidx] == '--help': print __doc__ exit(0) elif argv[argidx] == '-s': lsock = socket() lsock.bind(('',0)) # anonymous port lsock.listen(5) print "server listening at INADDR_ANY on: %s %s" % (gethostname(),lsock.getsockname()[1]) stdout.flush() (tsock,taddr) = lsock.accept() print "server has conn on %s from %s" % (tsock,taddr) msg = tsock.recv(64) if not msg: print "*** server failed to recv msg from client" else: print "server successfully recvd msg from client: %s" % (msg) tsock.sendall('ack_from_server_to_client') tsock.close() lsock.close() exit(0) elif argv[argidx] == '-c': sock = socket() sock.connect((argv[argidx+1],int(argv[argidx+2]))) # note double parens sock.sendall('hello_from_client_to_server') msg = sock.recv(64) if not msg: print "*** client failed to recv ack from server" else: print "client successfully recvd ack from server: %s" % (msg) stdout.flush() sock.close() exit(0) elif argv[argidx] == '-pc': print "--- print results of: gethostbyname_ex(gethostname())" print gethostbyname_ex(gethostname()) print "--- try to run /bin/hostname" linesAsStr = getoutput("/bin/hostname") print linesAsStr print "--- try to run uname -a" linesAsStr = getoutput("/bin/uname -a") print linesAsStr print "--- try to print /etc/hosts" linesAsStr = getoutput("/bin/cat /etc/hosts") print linesAsStr print "--- try to print /etc/resolv.conf" linesAsStr = getoutput("/bin/cat /etc/resolv.conf") print linesAsStr print "--- try to run /sbin/ifconfig -a" linesAsStr = getoutput("/sbin/ifconfig -a") print linesAsStr print "--- try to print /etc/nsswitch.conf" linesAsStr = getoutput("/bin/cat /etc/nsswitch.conf") print linesAsStr exit(0) elif argv[argidx] == '-v': verbose = 1 argidx += 1 elif argv[argidx] == '-l': long_messages = 1 argidx += 1 elif argv[argidx] == '-f': try: hostsFile = open(argv[argidx+1]) except: print 'unable to open file ', argv[argidx+1] exit(-1) for line in hostsFile: line = line.rstrip() if not line or line[0] == '#': continue splitLine = re.split(r'\s+',line) host = splitLine[0] if ':' in host: (host,ncpus) = host.split(':') hostsFromFile.append(host) argidx += 2 elif argv[argidx] == '-ssh': do_ssh = 1 argidx += 1 else: print 'unrecognized arg:', argv[argidx] exit(0) # See if we can do gethostXXX, etc. for this host if verbose: print 'obtaining hostname via gethostname and getfqdn' uqhn1 = gethostname() fqhn1 = getfqdn() if verbose: print "gethostname gives ", uqhn1 print "getfqdn gives ", fqhn1 if verbose: print 'checking out unqualified hostname; make sure is not "localhost", etc.' if uqhn1.startswith('localhost'): if long_messages: msg = """ ********** The unqualified hostname seems to be localhost. This generally means that the machine's hostname is not set. You may change it by using the 'hostname' command, e.g.: hostname mybox1 However, this will not remain after a reboot. To do this, you will need to consult the operating system's documentation. On Debian Linux systems, this can be done by: echo "mybox1" > /etc/hostname ********** """ else: msg = "*** the uq hostname seems to be localhost" print msg.strip().replace(' ','') elif uqhn1 == '': if long_messages: msg = """ ********** The unqualified hostname seems to be blank. This generally means that the machine's hostname is not set. You may change it by using the 'hostname' command, e.g.: hostname mybox1 However, this will not remain after a reboot. To do this, you will need to consult the operating system's documentation. On Debian Linux systems, this can be done by: echo "mybox1" > /etc/hostname ********** """ else: msg = "*** the uq hostname seems to be localhost" print msg.replace(' ','') if verbose: print 'checking out qualified hostname; make sure is not "localhost", etc.' if fqhn1.startswith('localhost'): if long_messages: msg = """ ********** Your fully qualified hostname seems to be set to 'localhost'. This generally means that your machine's /etc/hosts file contains a line similar to this: 127.0.0.1 mybox1 localhost.localdomain localhost You probably want to remove your hostname from this line and place it on a line by itself with your ipaddress, like this: $ipaddr mybox1 ********** """ else: msg = "*** the fq hostname seems to be localhost" print msg.rstrip().replace(' ','') elif fqhn1 == '': if long_messages: msg = """ ********** Your fully qualified hostname seems to be blank. ********** """ else: msg = "*** the fq hostname is blank" print msg.replace(' ','') if verbose: print 'obtain IP addrs via qualified and unqualified hostnames;', print ' make sure other than 127.0.0.1' uipaddr1 = 0 try: ghbnu = gethostbyname_ex(uqhn1) if verbose: print "gethostbyname_ex: ", ghbnu uipaddr1 = ghbnu[2][0] if uipaddr1.startswith('127'): if long_messages: msg = """ ********** Your unqualified hostname resolves to 127.0.0.1, which is the IP address reserved for localhost. This likely means that you have a line similar to this one in your /etc/hosts file: 127.0.0.1 $uqhn This should perhaps be changed to the following: 127.0.0.1 localhost.localdomain localhost ********** """ else: msg = "*** first ipaddr for this host (via %s) is: %s" % (uqhn1,uipaddr1) print msg.replace(' ','') try: ghbau = gethostbyaddr(uipaddr1) except: print "*** gethostbyaddr failed for this hosts's IP %s" % (uipaddr1) except: if long_messages: msg = """ ********** The system call gethostbyname(3) failed to resolve your unqualified hostname, or $uqhn. This can be caused by missing info from your /etc/hosts file or your system not having correctly configured name resolvers, or by your IP address not existing in resolution services. If you run DNS, you may wish to make sure that your DNS server has the correct forward A set up for yout machine's hostname. If you are not using DNS and are only using hosts files, please check that a line similar to the one below exists in your /etc/hosts file: $ipaddr $uqdn If you plan to use DNS but you are not sure that it is correctly configured, please check that the file /etc/resolv.conf contains entries similar to the following: nameserver 1.2.3.4 where 1.2.3.4 is an actual IP of one of your nameservers. ********** """ else: msg = "*** gethostbyname_ex failed for this host %s" % (uqhn1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -