Python's tail -f implementation for remote files

A

asdf

Basically what i want to do is to read a file
that is being constantly appended to but which
is located on a remote server.
I found this for doing BASH's tail -f in python:

import os
tailoutputfile = os.popen('tail -f syslog')
while 1:
line = tailoutputfile.readline()
if len(line)==0: # change the termination condition
break
process_line(line)

and it works great. But not sure how to use this with
ssh command to connect to remote machine.

Any tips?
 
D

Dikkie Dik

asdf said:
Basically what i want to do is to read a file
that is being constantly appended to but which
is located on a remote server.
I found this for doing BASH's tail -f in python:

import os
tailoutputfile = os.popen('tail -f syslog')
while 1:
line = tailoutputfile.readline()
if len(line)==0: # change the termination condition
break
process_line(line)

and it works great. But not sure how to use this with
ssh command to connect to remote machine.

Any tips?

ssh host_address 'tail -f file_name'

Should do it (from the command line). Off course, you can put this into
popen as well. If you log in with a public key (see ssh-keygen), you do
not have to supply a password using the console.

Best regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top