Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to read a remote file with logs from a remote host via SSH What is the most convenient way to do it if I have ssh access to the log folder ?

share|improve this question

6 Answers 6

Why do anything complicated? The following should work fine..

ssh server "cat /path/to/file"

If you want paging..

ssh server "cat /path/to/file" |less

share|improve this answer

The most convenient I would say is sshfs.

share|improve this answer

Vi, nano, less, etc.

share|improve this answer

I think you should definitely use a program on the remote host and open the file there, instead of downloading the file and opening on the client side / your side.

As far as I know Linux editing/reading tools such as 'vi' or 'less' read the file line by line, therefore you don't have to open the whole log file, you just open the parts and transfer them through ssh as you read. Other operating systems have similar programs but I can't recall the name of any.

I don't know if there is a way to load the file part-by-part to a client reader on SSH though.

share|improve this answer
    
ssh user@server "less /path/log" sums it up –  aciliketcap May 23 '10 at 13:48

I use:

ssh -t user@host "less ~/path/to/log.file"

The -t causes ssh to allocate a terminal, which allows you to interact with less as if it were running locally, including searching/scrolling/tailing, all without streaming the whole remote file to the local computer.

share|improve this answer

Following on what Warner suggested, but catering for the fact that log files can be quite large:

ssh server "tail -n 300 /path/to/log" | less

Will give you the last 300 lines to page through, rather then the entire log file.

share|improve this answer
    
If you're using less you can also navigate the results similar to how you would navigate a file in vi - G will take you to the end of the file, 1G will take you to the beginning, /regex will search for the given regular expression... –  voretaq7 Oct 11 '12 at 21:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.