Python file processing

I'm trying to get a script that loops through a list of servers, and does an iisreset.

Can someone help me out with this? I'm a little new, and I'm not sure why it fails. It's for windows. I had to use rstrip to get rid of \n. However, it seems to just say it's timing out, and not looping through the servers.

Thanks

import wmi, getpass
import sys
import os
import re

uname = raw_input(r"Username With Domain (Example: prod\a-bob.rick): ")
passwd = getpass.getpass()


file = open(sys.argv[1], "r")
line = file.readline().rstrip()
x = line
status = raw_input(r"Reset Web Server ")
if str(status).lower() == 'y':
    while line:
        try:
            print("attempting")
            c = wmi.WMI(computer=x, user=uname, password=passwd)
            process_id, return_value = c.Win32_Process.Create(CommandLine="iisreset")
            for process in c.Win32_Process(ProcessId=process_id):
                 result = "Success"
        except wmi.x_access_denied:
            print("access denied")
            result = 'Denied'
        except wmi.x_wmi:
             result = 'Timeout'
        except:
            result = 'Fail'
        print(x, result)

Open in new window

winthrup8Asked:
Who is Participating?
 
gelonidaConnect With a Mentor Commented:
There is an error in your while loop.

you should remove line 11

change line 15 to

for line in file:
    line = line.rstrip()
    x = line

I don't understand why you use the variable line and x if they store both the same value, but perhaps this is just because you simplified above example???
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.