8

Viewing and examining your error log via SSH

 3 years ago
source link: https://help.dreamhost.com/hc/en-us/articles/216512217-Viewing-and-examining-your-error-log-via-SSH
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Viewing and examining your error log via SSH

Overview

This article explains how to view your error log via SSH which requires some basic knowledge of a shell terminal. For an easier option using FTP, view the following article instead:

For troubleshooting purposes, you may sometimes need to check your site’s error logs and access logs to get more information as to why a problem may occur. This article explains how to view these logs through SFTP and Shell.

  • In order to view the logs, you must log in to your server and navigate to the logs/example.com/http directory.
  • Logs are rotated every night so that access.log and error.log only contain today’s logs, while error.log.0 and access.log.0 contain logs from the day before.
  • Log files are deleted shortly after this, so it’s recommended to check them as soon as possible.
  • Per GDPR, DreamHost stores HTTP logs by default for 3 days.

Viewing logs via SSH

  1. View the SSH overview article for instructions on how to log in to your server.
  2. Type in the following to change your directory to your user’s /logs directory:
    [server]$ cd ~/logs
  3. Type in the following to view all of the domains under the user:
    [server]$ ls -la
  4. cd into the desired domain's folder.
    [server]$ cd example.com
  5. cd into the domain's /http folder.
    [server]$ cd http
  6. Type in the following to view a list of your log files:
    [server]$ ls

Decompressing files that end with .gz

Older log files are compressed and end with .gz. View the following article for instructions on how to decompress those files:

Reading the most recent errors using the 'tail' command

The following shows various uses of the tail command that you can run within the appropriate directory to read specific parts of the log.

Use the command tail to read the last lines from a file. For example:

Command Description

[server]$ tail -n 10 error.log

Shows the last 10 lines from an error log.

[server]$ tail -f error.log

Shows all newly added lines from a log file in real-time on the shell.

[server]$ tail -n 100 error.log | more

Shows the last 100 lines a single line at a time using the more command.

  • Useful for showing more lines than will fit in your shell window.
  • Press the space bar to view the next line.
Ctrl + C Quits tail and returns to the command line.

Searching for a specific term using the "grep" command

You can use the grep command to search for a specific term within files. This is particularly helpful since looking through an error log can be tedious if a certain errors need to be seen and others can be ignored.

For example, if you only wanted to see errors related to the Testing2.jpg you can run this command:

[server]$ cat error.log | grep "Testing2.jpg"

The cat error.log command lists everything within the log. You may notice that several entries show “File does not exist” which are often irrelevant and can be ignored. You should always ensure that this is the case, however; If you’re sure they are not important, filter them out by running the following:

[server]$ cat error.log | grep -v "exist"

See also

Did this article answer your questions?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK