I am new to python programming. I have this problem: I have a list of text files (compressed and not), and I need: - connect to the server and open them - after opening the file I need to take its contents and pass it to another python function that I wrote
def readLogs (fileName): f = open (fileName, 'r') inStream = f.read() counter = 0 inStream = re.split('\n', inStream)
to clarify the information contained in these files. The function is designed to write only 1 line of logs that are stored in these files using 3 lines ... The function works fine with files read from my local machine, but I can’t figure out how to connect to the remote server and create these single-line logs without saving the contents of each file to a string, and then working with the string ... The command I use to connect to a remote computer is:
connection_out = Popen(['ssh', retList[0], 'cd '+retList[2]+'; cat'+fileName], stdout=PIPE).communicate()[0]
retList [0] and retList [2] are user @remote and the name of the folder I should be accessing
Thank you all in advance!
UPDATE:
My problem is that I have to establish an ssh connection first:
pr1=Popen(['ssh', ' siatc@lgssp101 ', '*~/XYZ/AAAAA/log_archive/00/MSG_090308_162648.gz*' ], stdout=PIPE).communicate()[0]
All the files that I need to open are stored in a list, fileList [], some of them are compressed (.gz), and some are only text files! I tried all the procedures that you showed before the bot didn’t work ... I think I changed the third argument of the Popen function, but I can’t figure out how to do it! Is there anyone who can help me?
python yield subprocess stream popen
wheisenberg
source share