-1

I am writing a script to kick off a bat script in several client systems. I'd like to capture each system that fails. The issue i have is that it cycles through the clients and then my IF statement is run at the end. This sounds like the IF statement is in the wrong place but the logic seems fine to me.

clients = open("C:\client.csv", 'r') failedclients=[]

def kickoff(clients):
      logging.info("Going through clients.csv")
      for host in clients:
            batkickoff = subprocess.call('C:\pstools\psexec.exe \\\\%s -d C:\test.bat' % hostname)
                if batkickoff != 1:
                  print "there was an issue"
                  logging.info(hostname + " had an issue kicking off")
              failedclients.append(hostname)     

kickoff(clients)

So it will cycle through and kick off the bat script in each client. It DOESN'T execute my IF statement until the last loop.

Any help is appreciated.

Thanks in advance

user2099445
  • 103
  • 7

1 Answers1

0

Are you sure that your script isn't just executing the if statement at each cycle, but batkickoff is 1 so the rest of the if statement is not executed ? (Perhaps the last client name is an end of file error or something like that). I completed the rest of your if loop so you can see if it is being executed or not :

  def kickoff(clients):
      logging.info("Going through clients.csv")
      for host in clients:
         batkickoff = subprocess.call('C:\pstools\psexec.exe \\\\%s -d C:\test.bat' % host)
         if batkickoff != 1:
             print "there was an issue"
             logging.info(host + " had an issue kicking off")
             failedclients.append(host)
         elif batkickoff == 1:
             logging.debug(host + "successfully executed")
         else:
             logging.debug("unknown error")

It may also be useful to check the contents of the clients variable being fed into your function to ensure that there was not an error in reading the csv.

Please let me know if this helps.

edit : I am assuming that there is more to this code than what you have posted here and that the indentation errors are due to copy-paste problems. hostname changed to host @Burhan Khalid