Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

View remote log files with Console and ssh UNIX
Ever wanted to grab a log file entries from a remote machine on your local machine? Here's one way to do it. In Terminal, connected to a remote host, run tail -f on the log file you want to view, and then direct the output to a local file with a .log extension. For example:
$ ssh remotehost "tail -f /var/log/httpd/access.log" >> remote-httpd.log
(You'll have to replace remotehost with the full name/IP address of the remote host, obviously.) Note that the command will not return a command prompt. Now launch Console, use File: Open within the application, and point it to the local file with the .log extension you named in the Terminal command.

Now you can use Console's features to view your remote log files in real time. When you want to stop the logging, switch back to Terminal and hit Control-C to stop the ssh command that is sitting in your Terminal window.
    •    
  • Currently 3.80 / 5
  You rated: 4 / 5 (5 votes cast)
 
[26,708 views]  

View remote log files with Console and ssh | 4 comments | Create New Account
Click here to return to the 'View remote log files with Console and ssh' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
View remote log files with Console and ssh
Authored by: mayo2ca on Jul 11, '06 11:16:57AM

Pointing out the obvious here, but if you are cool with seeing it in terminal, remove the ">> remote-httpd.log" bit and you'll see your log in terminal in tail.



[ Reply to This | # ]
View remote log files with Console and ssh
Authored by: legacyb4 on Jul 11, '06 10:40:13PM

Goes without saying that you can only view logs that you have permissions for...

---
lumine.net



[ Reply to This | # ]
View remote log files with Console and ssh
Authored by: legacyb4 on Jul 11, '06 10:43:58PM

Modify the command to be "sudo tail -f..." and you will be prompted for a sudo password.

---
lumine.net



[ Reply to This | # ]
View remote log files with Console and ssh
Authored by: ianeiloart on Jul 12, '06 02:24:57AM

This is a very cool tip. Of course, if you're happy with viewing the logs in the Terminal, you just shell in and tail the log.

Here's a few related tips:

Put the local copy of the log in

~Library/Logs/Remote
and you can use Console's "File...Open Quickly" feature.

If the log doesn't get updated frequently, you can use Console's alert features (see "Console...Preferences") - either bounce the icon in the dock or bring the window to the front when an event is logged.

Console's filter feature is good - type a word in the title bar, and only matching lines will be displayed. Unfortunately, all log updates will trigger the alerts - not just matching lines.

If you want to be alerted to specific events (like a rejection in a mail log), then use a command like this in conjunction with Console's alert features:

ssh mailserver "tail -f /var/exim/log/exim_smtp_mainlog" | grep 'rejected' >> Library/Logs/Remote/mailserver.smtp.log

Only matching lines will be put into the local copy. You can use egrep to do sophisticated pattern matching, if you like. For example:

ssh mailserver "tail -f /var/exim/log/exim_smtp_mainlog" | egrep -i 'apple|banana' >> Library/Logs/Remote/mailserver.smtp.log

will match lines containing either apple or banana, with case insensitivity.

---
--
Ian Eiloart

[ Reply to This | # ]