Saturday, 18 July 2020

The Linux ping command

LPI Tutorial and Material, LPI Study Materials, LPI Exam Prep, LPI Guides

Linux command FAQ: Can you share some examples of the Linux ping command?


You typically use the Linux ping command to test to see whether a remote server is up and running, or to test problems with a network. For instance, my internet connection here in Alaska tends to get flaky from time to time, and when things appear to be going bad, I use the ping command to verify the problem.

Basic ping example


In its basic use, you just issue the ping command followed by the name of a server or website, like this:

ping www.google.com

The ping command then sends little packets of information to the remote server, and if all goes well, they are acknowledged by that remote server. (From a security perspective, that remote server must also be configured to respond to ping requests. Some Linux administrators disable this feature.)

For instance, when my network connection is working fine, here's what the ping command results look like when I ping Google:

$ ping www.google.com

PING www.l.google.com (72.14.213.99): 56 data bytes
64 bytes from 72.14.213.99: icmp_seq=0 ttl=50 time=48.582 ms
64 bytes from 72.14.213.99: icmp_seq=1 ttl=50 time=48.655 ms
64 bytes from 72.14.213.99: icmp_seq=2 ttl=50 time=49.171 ms
64 bytes from 72.14.213.99: icmp_seq=3 ttl=50 time=50.554 ms
^C
--- www.l.google.com ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 48.582/49.204/50.554/0.691 ms

The thing I always look at is the "time" information, shown at the end of each line of output. For me, anything under 50 msec usually indicates that my network connection is working fine. When my network connection goes bad, the output of that time field fluctuates drastically (at which point I call my internet service provider).

One important thing to note: When you issue the ping command as shown, you normally use the [Control][c] key sequence to stop the command. That's how you do things on Linux, Unix, and Mac OS X systems; the last time I tried this on Windows the ping command ran for only a few times and then stopped itself, so things may still be different there.

The Linux ping command - Controlling the number of pings


If you remember the movie The Hunt for Red October, there's a point at which Sean Connery is in the submarine, and he tells the other man, "Give me one ping." This was a pretty funny moment for Unix administrators like myself who had used the ping command for so many years, because it was a great, real world description of the ping command.

It also demonstrated something else: There are times when you don't want the ping command to run forever, you may just want to issue one ping, five pings, or ten pings, etc. In that case, you use the -c option ("count") of the ping command to control the number of pings issued, like this:

$ ping -c 5 www.google.com

PING www.l.google.com (74.125.53.105): 56 data bytes
64 bytes from 74.125.53.105: icmp_seq=0 ttl=50 time=49.198 ms
64 bytes from 74.125.53.105: icmp_seq=1 ttl=50 time=46.662 ms
64 bytes from 74.125.53.105: icmp_seq=2 ttl=50 time=52.202 ms
64 bytes from 74.125.53.105: icmp_seq=3 ttl=50 time=50.108 ms
64 bytes from 74.125.53.105: icmp_seq=4 ttl=50 time=51.690 ms

--- www.l.google.com ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/stddev = 46.662/49.972/52.202/1.975 ms

Ping a specific port


You can also use the ping command to ping a port on a Unix or Linux system. Here's the description from the Linux ping man page:

-p port

Set the base UDP port number used in probes. This
option  is  used  with the -U option. The default
base port  number  is  33434.  The  ping  utility
starts setting the destination port number of UDP
packets to this base and increments it by one  at
each probe.

Honestly, I don't know much about this, and I don't have a need for this, so I'll leave it at that. One writer suggested using a port-scanning tool named nmap if you need to "ping" a port. nmap lets you see whether ports are "open" (listening), and I use it to test open ports on firewall setups, so in regards to trying to "ping a port", that's a good suggestion.

More Unix/Linux ping command information


There are more things you can do with the Unix/Linux ping command, but far and away these are the most common ping command options I use. For more information, use the Unix man command to get more information on the ping command, like this:

man ping

One final note about the ping command: It has become much more common for Unix and Linux administrators to turn off the ping command on their servers. So, if you can't ping one of your own servers, make sure you have the ping service enabled on that server, or that a firewall isn't blocking your ping attempts.

Thursday, 16 July 2020

Linux `sort` command examples

Sort Command, LPI Exam Prep, LPI Study Materials, LPI Learning, LPI Guides, Linux Command, Unix Command

Linux sort command FAQ: Can you share some examples of the Unix/Linux sort command?

As its name implies, the Unix/Linux sort command lets you sort text information. This article shares several examples of the Linux sort command.

Sorting `ls` command output


You can use the Linux sort command to sort all kinds of output from other commands. For instance, here's an example where I sort the output of the ls -al command:

$ ls -al | sort -n -k5

This results in the following ls command sorted output, which as you can see, is a directory listing, sorted by filesize (the 5th column):

-rw-r--r--   1 al  al       0 Aug 17  2007 CreateAPodcast.idx
total 992
-rw-r--r--   1 al  al     240 Aug 17  2007 files
drwxr-xr-x  11 al  al     374 Jul  5 17:50 ..
-rw-r--r--   1 al  al     535 Aug 18  2007 CreateAPodcast.out
drwxr-xr-x  18 al  al     612 Aug 18  2007 images
drwxr-xr-x  20 al  al     680 Aug 27  2007 .
-rw-r--r--   1 al  al     978 Aug 18  2007 CreateAPodcast.toc
-rw-r--r--   1 al  al    1425 Aug 18  2007 CreateAPodcast.lof
drwxr-xr-x  50 al  al    1700 Aug 18  2007 CreateAPodcast
-rwxr-xr-x@  1 al  al    2716 Aug 18  2007 CreateAPodcast.tex
-rw-r--r--   1 al  al    4431 Aug 18  2007 CreateAPodcast.aux
-rw-r--r--@  1 al  al    9689 Aug 17  2007 CAPContent2.rga copy
-rw-r--r--   1 al  al   13564 Aug 18  2007 CreateAPodcast.log
-rw-r--r--@  1 al  al   14369 Aug 18  2007 CAPContent2.tex
-rw-r--r--@  1 al  al   14738 Aug 31  2007 CAPContent2.rga
-rw-r--r--@  1 al  al  310657 Aug 18  2007 create-a-podcast-2.mp3

The -n in my example means "sort numerically", and the -k5 option means to key off of column five. Like other Unix commands, these sort command options can be combined and shortened, like this:

$ ls -al | sort -nk5

which yields the same output.

(ls now has a sort option; I just showed this as an example.)

Sorting output of the ‘ps’ command


From time to time you'll want to sort the output of the Linux ps command, and again here, the sort command can be your friend. You can just sort alphabetically by the first column (username):

$ ps auxw | sort

Or you can sort numerically by column two (the PID field):

$ ps auxw | sort -nk2

You can also reverse that sort with the -r option:

$ ps auxw | sort -rnk2

Sorting file contents with ‘cat’


You can also sort the contents of a file with the Linux sort command. Here's what a file named files looks like before I sort it:

$ cat files

1-gb-startup.jpg
10-after-drum.jpg
2-use-for-buttons.jpg
3-after-media-button.jpg
4-after-loop-browser.jpg
5-after-jingles.jpg
6-after-male-voice.jpg
7-after-chipmunk.jpg
8-before-2nd-male-recording.jpg
9-after-2nd-male-recording.jpg

And here's the output when I run a simple sort command against it:

$ sort files

1-gb-startup.jpg
10-after-drum.jpg
2-use-for-buttons.jpg
3-after-media-button.jpg
4-after-loop-browser.jpg
5-after-jingles.jpg
6-after-male-voice.jpg
7-after-chipmunk.jpg
8-before-2nd-male-recording.jpg
9-after-2nd-male-recording.jpg

It's very important to note that this command does not sort the actual file, it just displays the sorted output on your terminal. To have the sorted output to another file, you'd run a command like this:

$ sort files > files.sorted

which creates a new file named files.sorted, which contains the new, sorted output.

Linux `sort` help

The output from the sort --help command is pretty short, so I'll include it here:

$ sort --help

Usage: sort [OPTION]... [FILE]...
Write sorted concatenation of all FILE(s) to standard output.

Mandatory arguments to long options are mandatory for short options too.
Ordering options:

  -b, --ignore-leading-blanks  ignore leading blanks
  -d, --dictionary-order      consider only blanks and alphanumeric characters
  -f, --ignore-case           fold lower case to upper case characters
  -g, --general-numeric-sort  compare according to general numerical value
  -i, --ignore-nonprinting    consider only printable characters
  -M, --month-sort            compare (unknown) < `JAN' < ... < `DEC'
  -n, --numeric-sort          compare according to string numerical value
  -r, --reverse               reverse the result of comparisons

Other options:

  -c, --check               check whether input is sorted; do not sort
  -k, --key=POS1[,POS2]     start a key at POS1, end it at POS2 (origin 1)
  -m, --merge               merge already sorted files; do not sort
  -o, --output=FILE         write result to FILE instead of standard output
  -s, --stable              stabilize sort by disabling last-resort comparison
  -S, --buffer-size=SIZE    use SIZE for main memory buffer
  -t, --field-separator=SEP  use SEP instead of non-blank to blank transition
  -T, --temporary-directory=DIR  use DIR for temporaries, not $TMPDIR or /tmp;
                              multiple options specify multiple directories
  -u, --unique              with -c, check for strict ordering;
                              without -c, output only the first of an equal run
  -z, --zero-terminated     end lines with 0 byte, not newline
      --help     display this help and exit
      --version  output version information and exit

POS is F[.C][OPTS], where F is the field number and C the character position
in the field.  OPTS is one or more single-letter ordering options, which
override global ordering options for that key.  If no key is given, use the
entire line as the key.

SIZE may be followed by the following multiplicative suffixes:
% 1% of memory, b 1, K 1024 (default), and so on for M, G, T, P, E, Z, Y.

With no FILE, or when FILE is -, read standard input.

*** WARNING ***
The locale specified by the environment affects sort order.
Set LC_ALL=C to get the traditional sort order that uses
native byte values.

Report bugs to <bug-coreutils@gnu.org>.

Tuesday, 14 July 2020

LPIC-3 304: Virtualization and High Availability

LPIC-3 304, LPI Tutorial and Material, LPI Exam Prep, LPI Certification, LPI Learning, LPI Prep

The LPIC-3 certification is the culmination of LPI’s multi-level professional certification program. LPIC-3 is designed for the enterprise-level Linux professional and represents the highest level of professional, distribution-neutral Linux certification within the industry. Three separate LPIC-3 specialty certifications are available. Passing any one of the three exams will grant the LPIC-3 certification for that specialty.

The LPIC-3 304: Virtualization and High Availability certification covers the administration of Linux systems enterprise-wide with an emphasis on Virtualization & High Availability.

Current Version: 2.0 (Exam code 304-200)

Objectives: 304-200

Prerequisites: The candidate must have an active LPIC-2 certification to receive LPIC-3 certification

Requirements: Passing the 304 exam

Validity Period: 5 years

Cost: Click here for exam pricing in your country.

Languages: English, Japanese

LPIC-3 Exam 304 Topics


1. Virtualization
2. High Availability Cluster Management
3. High Availability Cluster Storage

Also Read: LPIC-3 304: Virtualization and High Availability

Saturday, 11 July 2020

Open Technology: Linux Professional Institute DevOps Tools Engineer

LPI Study Materials, LPI Exam Prep, LPI Guides, LPI Tutorial and Material, LPI Certification

The Open Technology professional certifications are designed to evaluate the knowledge and skills of open technology tools, such as DevOps tools and BSD Specialist. To keep pace with evolving technologies, open technology track exam objectives are updated on average every three years and certifications are valid for five years before you must recertify or certify at a higher level.

For Open Technology certifications, single exam is awarded with certification, and there are no prerequisites for the exams.

Businesses across the globe are increasingly implementing DevOps practices to optimize daily systems administration and software development tasks. As a result, businesses across industries are hiring IT professionals that can effectively apply DevOps to reduce delivery time and improve quality in the development of new software products.

To meet this growing need for qualified professionals, LPI developed the Linux Professional Institute DevOps Tools Engineer certification which verifies the skills needed to use the tools that enhance collaboration in workflows throughout system administration and software development.

In developing the Linux Professional Institute DevOps Tools Engineer certification, LPI reviewed the DevOps tools landscape and defined a set of essential skills when applying DevOps. As such, the certification exam focuses on the practical skills required to work successfully in a DevOps environment – focusing on the skills needed to use the most prominent DevOps tools. The result is a certification that covers the intersection between development and operations, making it relevant for all IT professionals working in the field of DevOps.

Current Version: 1.0 (Exam code 701-100)

Objectives: 701-100

Prerequisites: There are no prerequisites for this certification.

Requirements: Pass the Linux Professional Institute DevOps Tools Engineer exam. The 90-minute exam consists of 60 multiple choice and fill-in-the-blank questions.

Validity Period: 5 years

Cost: Click here for exam pricing in your country.

Languages: English, Japanese

LPI Study Materials, LPI Exam Prep, LPI Guides, LPI Tutorial and Material, LPI Certification
To receive the Linux Professional Institute DevOps Tools Engineer Certification the candidate must:

◉ Have a working knowledge of DevOps-related domains such as Software Engineering and Architecture, Container and Machine Deployment, Configuration Management and Monitoring.

◉ Have proficiency in prominent free and open source utilities such as Docker, Vagrant, Ansible, Puppet, Git, and Jenkins.

Also Read: LPIC-OT Exam 701: DevOps Tools Engineer

Tuesday, 7 July 2020

Linux mail - a Linux shell script to send mail

Linux Mail, LPI Study Material, LPI Exam Prep, LPI Tutorial and Material, LPI Study Material

Here's a n example Linux shell script (Bourne shell to be specific) that I use to send a list of directories to one of our invoicers. She uses this list as part of a cross-checking process to make sure she bills each one of our customers who have a directory allocated to them. The list is sent to her automatically from a Linux crontab entry I created for her.

Also Read: 101-500: Linux Administrator - 101 (LPIC-1 101)

Without any further ado, here is the Linux shell script that sends the email. (Note that although I keep writing "Linux mail", this should also work on other Unix systems.)

Example Linux shell script - sending mail


Here's the source code for the Linux shell script that sends the email message out every day:

#!/bin/sh

cd /home/lpicentral/bin

echo "

DO NOT REPLY TO THIS EMAIL MESSAGE.

This is a list of the current customer directories installed on our server.
Please make sure they are all billed.

"                       >  listOfWebSites
ls -1 /customers        >> listOfWebSites

mail -s "Current customer directories on our server" kim@herdomain.com < listOfWebSites

That script creates a file named listOfWebSites, then sends that file via the standard Linux mail command.

Corresponding Linux crontab entry


Here is the crontab entry that I use to send this email message every day. If you're familiar with the crontab format you should be able to easily figure out the date and time this information is mailed to here.

30 7 12 * * /home/lpicentral/bin/mailWebSitesToKim

I thought this was a pretty decent use of shell scripting and the built-in Linux mail command. Notice how easy the Unix operating system and redirection operators make this.

Saturday, 4 July 2020

How to use the Linux cut command with a field and delimiter

Linux Tutorial and Material, Linux Exam Prep, Linux Certification, LPI Prep

Should you ever run into a situation where you want to use the Linux cut command by specifying both a field number and field delimiter, I hope this example is helpful for you.

I was just working on a problem where I wanted to list all the fonts on a Mac OS X (Unix) system, and needed to use the cut command this way. A straight listing of all the filenames in the Mac font directory gave me a long list of names like this:

$ ls -1

AScore.ttf.11904_0.ATSD
AScore.ttf.11904_0.fontinfo
AScoreParts.ttf.122A0_0.ATSD
AScoreParts.ttf.122A0_0.fontinfo
Abadi MT Condensed Extra Bold.0_11005.ATSD
Abadi MT Condensed Extra Bold.0_11005.fontinfo

(There are actually 761 files on my current system, so I omitted a lot of output.)

For my needs, I just wanted the first part of each filename, i.e., the text string to the left of the first decimal in each filename, like this:

AScore
AScoreParts
Abadi MT Condensed Extra Bold

In short, to create this list, I used the following Unix cut command, specifying the desired field number and field delimiter:

$ ls -1 | cut -f1 -d'.'

This command can be read like this:

◉ Create a single column list of all files in the current directory.

◉ From that list, only print the first field of each filename, where the field delimiter is the "." character.

Running this command gave me the output I wanted:

AScore
AScoreParts
Abadi MT Condensed Extra Bold

More cut command examples


As a few more quick cut command examples, had I wanted to print the second field of each filename, I would have used this command:

$ ls -1 | cut -f2 -d'.'

If it made sense to use a space as the field delimiter, my cut command would have looked like this:

$ ls -1 | cut -f2 -d' '

And for something a little different, if I wanted to print all the usernames out of the /etc/passwd file on my Unix system, I can use this cut command:

$ cut -f1 -d: /etc/passwd

In that example, I'm again printing field one, but this time I'm using the ":" character as the field delimiter, and I'm reading directly from a file named /etc/passwd, instead of reading from standard input.