7

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 ?

6 Answers 6

11

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

2
  • Can you please let us know how to provide password in ssh command in a single line ? Dec 14, 2016 at 10:50
  • ssh -i ~/.ssh/my_key account@server "tail -f /path/to/file" Feb 9, 2017 at 0:12
5

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.

0
2

The most convenient I would say is sshfs.

2

Vi, nano, less, etc.

1

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.

1
  • ssh user@server "less /path/log" sums it up May 23, 2010 at 13:48
0

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.

1
  • 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, 2012 at 21:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .