Read Log.txt from the Remote Server on the Local Server in Real Time

5

These days passed the idea (I must have read somewhere and refreshed) to have a program on the local server that is synchronized with the remote server, where in this program I can see in real time the log file of the server, thus facilitating and making it quicker to fix an error (which I supposedly requested to be written there).

How? If so, which one (s) would be?

    
asked by anonymous 28.08.2015 / 20:50

3 answers

4

I know that in Windows when I need something like Plink utility, Putty that via SSH runs commands on a remote server bringing the remote control for Windows.

Something like this, for example:

plink DEBIAN_SSH cat /var/log/messages

Plink is an SSH utility so it does nothing more than run a command on the remote server and brings its output back, all using SSH.

So if the local server is also Linux, you can use direct SSH:

ssh [USER-NAME]@[REMOTE-HOST] cat /var/log/messages
  • Obviously this command can only be executed as ROOT or if the user that logs has permission in VISUDO for example.

  • It is also worth mentioning that you need to have an access key on the local server that allows remote connection without requiring a password on the remote server, otherwise the command will require a password. See this link if you need create a pair of keys for access.

But I believe that is the way.

If you want to monitor the real-time log output, the correct command is:

tail -f /var/log/messages

References in the links and also in the link below. link

    
31.08.2015 / 19:23
3

Use the multitail program. With it you can see two (or more) logs at the same time, rendered on the command line in the same window or in separate windows.

Official site: link

Some examples:

To view two local logs at a time:

multitail /var/log/apache2/error.log /var/log/apache2/error.log.1

To view two local logs at a time, each in one color:

multitail -ci green /var/log/yum.log -ci yellow -I /var/log/mysqld.log

To see two local logs in two columns:

multitail -s 2 /var/log/mysqld.log /var/log/xferlog

To see two remote logs, each on a machine at the same time:

multitail -l 'ssh [email protected] "tail -f /var/log/nginx/access.log"' -l 'ssh [email protected] "tail -f /var/log/nginx/access.log"'
    
31.08.2015 / 19:44
2

If both servers use Linux as OS, a good option is to use SSHFS. This allows you to have a remote folder mounted as a partition on the local system and does not need any complicated configuration - just access SSH to the remote server. To mount a folder with logs from the remote server just do:

sshfs utilizador@sistema_remoto:/var/logs/nginx/ /opt/remote_logs

After that you will be able to read the remote logs from the /opt/remote_logs folder usually.

Systems such as Ubuntu or Debian have the sshfs package already in their repositories.

    
31.08.2015 / 23:05