Overview
While investigating an issue on your Xinet Server, you want to identify a way to analyze the logs directly from the command line. You can inspect the log files directly on the server using commands such as less
, more
, grep
, or cat
.
It is better to parse the log content with specific keywords to find the most helpful information quickly.
Solution
There are several logs available within a Xinet Server environment that can make understanding the cause of issues easier. The directories below are the most common locations where these logs are stored:
- /usr/adm/appletalk/
- /var/adm/webnative/
- /var/spool/cups
- /var/log/
Many of these logs can be accessed directly from the command line by first navigating into their directory. We will use venture.log as an example throughout this article, but you can utilize these steps for any Xinet or 3rd-party package logs on your Linux Server.
-
Log into the Xinet Server from the terminal via SSH (Secure Shell) as a sudo user.
# ssh <YourSudoUser>@<YourServerIP/Domain>
-
Navigate to the directory containing the log file you want to review.
-
For our example, the venture.log, you can use the command below:
# cd /usr/adm/appletalk
.
-
- Use the commands below to open & review the log file.
The more
command
The more
utility is a filter for paging through text one screenful at a time from a target file. It is often compared with the less
command, which fills a similar purpose as a lightweight file browser. You can page down to review file contents using more
, but it doesn't support scrolling backward in the file, which is the main difference between more
and less
(which has been later introduced in Unix/Linux systems to resolve this limitation).
One of its main benefits is that it prints the content of the target file into your terminal, which can make actioning further commands based on the output much more manageable. As it prints one screenful at a time, the number of lines printed will depend on the size of your terminal window.
See # man more
to review its manual page for more information about this utility.
Usage:
# more venture.log
Space
can be used to advance through pages.Q
can be used to closemore
.
Example Output:
Note: Here, you can see the potential value of directly piping the target file content into the terminal.
The less
command
Less
is a program similar to more, but which allows backward and forward movement in the file. Also, less
does not have to read the entire input file before starting, so with large input files, it starts up faster than text editors like vi
.
Contrary to more
, less
does not output the content of the target file to the terminal, which can be helpful for quickly reviewing a file's content while maintaining a working terminal session. In many ways, less
is the opposite of more
.
See # man less
to review its manual page for more information about this utility.
Usage:
# less venture.log
-
Up and Down
arrow keys allow moving one line up or down in the file. -
Shift+G
can be used to go to the bottom of the log file (the most recent entries appear here). -
G
pressed twice brings you to the top of the file. -
Q
can be used to exit the current file.
Example Output:
Note: Notice that after closing the less
session (via pressing Q
), the terminal is not cluttered with the target file's content.
The cat
command
The cat
command is short for concatenate, and it simply prints the full content of a file to the terminal, similar to more
(detailed above). This is one of the more straightforward and useful commands for reviewing the content of files from the command line. When combined with I/O pipes and grep
, it can allow you to collect important details from a verbose log file quickly.
See # man cat
to review its manual page for more information about this utility.
Usage:
# cat venture.log
Example Output:
Note: For the example above, we are executing cat
on an example log containing five lines, as shown. See how the entire file contents will fill the terminal. This is important to remember when using cat
on extensive logs without the use of other filters.
The grep
command
The grep
command allows you to run searches for patterns in a target file. These patterns will be one or more patterns separated by newline characters and grep
prints each line that matches a pattern to the terminal.
On its own, grep
can be helpful for quickly locating a particular file containing a string pattern. Using a combination of cat
, pipe
, and grep command
is a common method of looking for the problems reported in error logs, especially if we know that words like error, fail, or warning will be shown in the log.
See # man grep
to review its manual page for more information about this utility.
Example Usage:
- Collecting information related to the backup operations:
# cat venture.log | grep backup
- Collecting information related to the backup failures:
# cat venture.log | grep fail
- Collecting information related to the volume sync:
# cat venture.log | grep sync
- Collecting information related to the license-related entries:
# cat venture.log | grep licen
Note: The grep
command has several additional options flags that can be used to help refine your search. For example, if you want to ignore the search string case, you can include the "-i" option. This will match every word regardless if it is uppercase or lowercase.
Consider the below example output of grep
with and without the "-i" option:
Comments
0 comments
Article is closed for comments.