while loop to read file ends prematurely

后端 未结 4 1882
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 08:29

The eventual goal is to have my bash script execute a command on multiple servers. I almost have it set up. My SSH authentication is working, but this simple while loop is

4条回答
  •  我在风中等你
    2021-01-06 08:51

    maybe with python XD

    #!/usr/bin/python
    
    import sys
    import Queue
    from subprocess import call
    
    logfile = sys.argv[1]
    q = Queue.Queue()
    
    with open(logfile) as data:
        datalines = (line.rstrip('\r\n') for line in data)
        for line in datalines:
            q.put(line)
    
    
    while not q.empty() :
        host = q.get()
        print "++++++ " + host + " ++++++"
        call(["ssh", host, "uname -a"])
        call(["ssh", host, "oslevel -s"])
        print "++++++++++++++++++++++++++"
    

提交回复
热议问题