0

Am trying to create inventory report for set of windows servers using following function. But, this function always fails ping test for all hosts, though am apple to ping a few of them cleanly from command line. tried multiple combination, not able to figure out what is limiting it from hitting ping pass block ? please suggest,

def StartInvetoryCollection() :
    for eachline in open('HostList.txt', 'r') :
        RemoteHost = eachline.strip()
        print(RemoteHost, end='')
        if os.system('ping RemoteHost -c 4') == 0 :
            print('\t\tPING=PASS',end='')
            ReportFileName = RemoteHost + '_msinfo.txt'
            os.system('msinfo32 /computer Host /report ReportFileName')
            print('\tData Collection=PASS')
        else :
            print('\t\tPING=FAIL\tData Collection=SKIP')
            pass

Hostlist.txt - contains one hostname per line

1 Answers1

0

You have to pass your value into the os.system:

def StartInvetoryCollection() :
    for eachline in open('HostList.txt', 'r') :
        RemoteHost = eachline.strip()
        print(RemoteHost, end='')
        if os.system('ping {} -n 4'.format(RemoteHost)) == 0 :
            print('\t\tPING=PASS',end='')
            ReportFileName = RemoteHost + '_msinfo.txt'
            os.system('msinfo32 /computer Host /report {}'.format(ReportFileName))
            print('\tData Collection=PASS')
        else :
            print('\t\tPING=FAIL\tData Collection=SKIP')
            pass
Tiny.D
  • 6,466
  • 2
  • 15
  • 20