By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 2,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

Python's tail -f implementation for remote files

P: n/a
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?
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
asdf wrote:
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.
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.