I'm trying to use a "python loop through list" and execute a command on each line from the list found and in between sleep to give it time to finish that command.
Here my script. I know it's the basic, but some one can help me to help me in put this script together. I'm using an old server with python 2.4 so I cannot use check_out or subprocess.
Thanks

import os
import sys
import time 

f=open('nserver.txt')

for line in f:
      os.system(/usr/local/sbin/script) + line
     time.sleep(5) # delays for 5 seconds    
f.close()

Recommended Answers

All 3 Replies

You could download subprocess.py from the python 2.7 distribution and try to use its methods. If your server is a linux server, it may work.

Command you has to be string and you concatenate "line" inside os.system().
So if i have i list of words and want to now lenght of each word,
i can use linux command expr length.
The command get executed on each line of words.txt.

import os
import time

f = open('words.txt')
for line in f:
    line = line.strip()
    time.sleep(5)
    os.system('expr length ' + line)
f.close()    

Thanks that works. I was not sure how to concatenate the list with with command.

Pirulo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.