How Do You Send an Email from the Command Prompt of Linux to a Long List of Recipients?

Problem scenarios
One or both of the following apply:

#1 You want to automate the sending of the exact same email to multiple people. You do not want to manually type in the recipients. You have the same subject and body that each recipient should receive. You want to customize the "from address" that the recipients see. How do you do this?

OR

#2 You are using the mail command on a Linux server. You want to customize the "from" address in the emails that you send. What do you do?

Solution
Prerequisites
You have installed mailx. If you are using a Red Hat derivative (e.g., CentOS/RHEL/Fedora), run this command: sudo yum -y install mailx

Solution
1. Create a file called list.csv. In it, put your email addresses inside. They should be separated by a comma. A space can be after the comma, but need not be.
2. Draft then use a command like this:

echo "payLoad of Message" | mail -s "placeSubjectHere" -r email@from.com $(cat list.csv)

-replace "payload of Message" with the message you want to send
-replace "placeSubjectHere" with the subject of your email
-replace "email@from.com" with the email address that you want the email to appear to be from

An Alternative Way To Send Email
Another way to do this is with Python; to learn how to use Python and not install anything else, see this external posting.

How Do You Programmatically Search Hyperlinks on a Given Webpage?

Problem scenario
You have a web page that you access from the front-end (e.g., a web browser). You want to see if there is a hyperlink on the page that goes to a certain URL. You know the web page and the URL, but you are not sure if a hyperlink on the website has such a link. What should you do?

Solution
Use the curl command. From a Linux command prompt, type this:

# Replace <URL of web page> with the web page you that has hyperlinks
# Replace "stringYouSearch" with an all-lowercase pattern that the hyperlink you are searching for
curl http://<URL of web page> | grep -i stringYouSearch

How Do You Troubleshoot the Puppet Error “file mode specification must be a string, not ‘Integer'”?

Problem scenario
You are running a manifest and you get this error:

Error: Failed to apply catalog: Parameter mode failed on File[/opt/hadoop/hadoop-2.2.0.tar.gz]: The file mode specification must be a string, not 'Integer' at /etc/puppetlabs/code/environments/production/modules/hadoop/manifests/init.pp:55

What is wrong?

Solution
Go to the Puppet Master server and open the file in the error. (The error provides the full directory path.) Go to the line number that the error message specifies. Find a file {} block section that looks something like this:

file { "${hadoop::params::hadoop_base}/hadoop-${hadoop::params::version}.tar.gz":
         mode => 0664,
         ensure => present,
         owner => "${hadoop::params::hadoop_path_owner}",
         group => "${hadoop::params::hadoop_group}",
         alias => "hadoop-source-tgz",
         before => Exec["untar-hadoop"],
         require => [File["hadoop-base"], Exec["download-hadoop"]],
     }

Translate the mode from octal notation to symbolic notation. If you do not know how, go to this website.

Enter the number in the website form and click "Submit." Change the Puppet manifest accordingly. In this example, the 'mode => 0664' line will need to be changed to 'mode => "u=rw,g=rw,o=r"'.

The website will show columns for user, group and other. These correspond to u, g, and o. The equals sign "=" assigns different permissions such as read, write or execute. Those permissions are symbolized with "r", "w", and "x" respectively.

How Do You Create a Puppet Manifest to Install Java?

Problem scenario
You have Puppet agent and Puppet Master set up and configured to work together. You are are running open source Puppet 5.x on Ubuntu servers in AWS. You want to install Java on the Puppet agent nodes. You tried to use the Java module.

On the Puppet Master server, you ran this: puppet module install puppetlabs-java --version 2.2.0

This is your site.pp file:

class { 'java' :
   package => 'java-1.8.0-openjdk-devel',
 }

You ran this command sudo puppet apply site.pp on the Puppet master but you got this:

Error: Evaluation Error: Error while evaluating a Resource Statement, Could not find declared class puppetlabs-java at /etc/puppetlabs/code/environments/production/manifests/site.pp:11:1 on node

On the Puppet agent node you ran sudo /opt/puppetlabs/bin/puppet agent -t -d and you received this message:

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Could not find declared class java at /etc/puppetlabs/code/environments/production/manifests/site.pp:11:1 on node ip-172-31-11-23.us-east-2.compute.internal
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

How do you create a manifest to deploy Java?

Solution
Install the Puppet module with the sudo command. If you do not use sudo, it will seem to work. But the 500 error with the Puppet agent is a tell-tale sign of using the Puppet module command without sudo. The inability to find the declared class on the Puppet Master server is another example of having installed a Puppet module without using the sudo command.

Finally the manifest should be changed to this:

class { 'java':
   distribution => 'jre',
 }

Run java -version to find that openjdk version 1.8 has been installed.

How Do You Capture More Events in the Nginx Logs?

Problem scenario
You want more verbose log capturing in Nginx. What should you do?

Solution
1. Make a back up of nginx.conf. Then open it. It is often in /etc/nginx/nginx.conf. (Some versions of nginx have a file that does some of the same things called default.conf. This will be the file you will need if you have no nginx.conf file.)

2. Find this stanza:

error_log /var/log/nginx/error.log;

Change it to be like this:

error_log /var/log/nginx/error.log debug;

3. Restart nginx. The error.log will have much more information. If you stop the Nginx service, this will be logged in error.log. You will also see malloc calls (memory allocation calls) and other vestiges of the C language. (Nginx was written in C.) This information can help you troubleshoot.

How Do You Troubleshoot Puppet Agent with a “Failed to open TCP connection…connection refused port 8140” error?

Problem scenario
You run puppet agent but you get this error:

Error: Could not request certificate: Failed to open TCP connection to puppetmaster.domain.com:8140 (Connection refused - connect(2) for "puppetmaster.domain.com" port 8140)

What do you do?

Solution
Ensure port 8140 is open. Install nmap on a server, and run this command:

nmap -p 8140 puppetmaster.domain.com

If you see this

PORT STATE SERVICE
8140/tcp closed unknown

Then the Puppet Master service is not running. Start the puppet master service (e.g., sudo puppet master start). If you need help installing Puppet Master, see this link for Ubuntu and this link for RedHat.

If you get a message showing that port 8140 is filtered, change the Security Group (in AWS), the Network Security Group (in Azure) or the firewall between the two servers.

How Do You Troubleshoot the Puppet Problem “Error 500 on SERVER: … Could not find node statement with name ‘default’ or “?

Problem scenario
You run the Puppet agent on a server but you receive this error:

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Could not find node statement with name 'default' or 'ip-172-31-20-105.us-east-2.compute.internal, ip-172-31-20-105.us-east-2.compute, ip-172-31-20-105.us-east-2, ip-172-31-20-105' on node ip-172-31-20-105.us-east-2.compute.internal
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

What should you do?

Solution
Is your Puppet manifest using a regex? For example, if your manifest is supposed to use wildcard variables and match the FQDN of the Puppet Agent node that gives this error, the variables do not seem to be matching up. Try to re-write the manifest so there is a "default" or explicit FQDN of the Puppet Agent. Then this error will go away.

How Do You Send an Email via a Postfix Server on Linux with the Command Prompt That Has Multiple Recipients and a Subject?

Problem scenario
You want to send one email to multiple people. You tried separating the email addresses with a comma or semicolon but you received this message: "555 5.5.4 Unsupported option:"

You do not know how to send an email with a subject via the Postfix command prompt. How do you send an email to multiple people with "Re:" content of your choice?

Solution
Prerequisite
You need to have Postfix installed and configured. If you are using a RedHat distribution (e.g., a CentOS or Fedora distribution), see this posting. If you are using an Ubuntu or Debian distribution, you may want to see if the RedHat posting directions can help you, but Postfix may already be installed and semi-configured. If you need assistance doing this with Linux SUSE, see this posting.

Procedure
Run these commands:

telnet <mail hostname> 25
helo <mail hostname>

mail from: yourname@yourdomainname.com

rcpt to:  first@emailaddress.com
rcpt to:  second@example.com
rcpt to:  another@person.com
DATA
Subject:  Your Subject Here
all the content you want here.  It is your message.
.

An Alternative Way To Send Email
Another way to do this is with Python; to learn how to use Python and not install anything else, see this external posting.

How Do You Print out Lines of a File One-by-One with No Commas and No Semicolons from a Linux Shell?

Problem scenario
You have a flat file that may have lines that terminate (or end) with semicolons or commas. You want to print one line of this file at a time without commas or semicolons. How do you do this with Linux?

Prerequisite
You have a file named "list" (with no extension) in the same directory as this script below.

Solution
Run this Bash script:

while read list; do
   var1=$(echo $list | sed 's/,//g') # remove the comma if any
   var1=$(echo $var1 | sed 's/;//g')
   echo $var1
 done <list

How Do You Automate a telnet Session to Send a Postfix Email on a Linux Server?

Problem scenario
You want to create a script that will send an email from a Linux server. You want it to use telnet. How do you automatically send an email using telnet?

Solution
Prerequisite
Set up Postfix. If you are running SUSE, see this posting. If you are running a RedHat derivative, see this posting.

Procedures
Use this script, but change the email addresses before you run it. source@from.com is the email that you want the email to appear to be from. destination@goingto.com is the email address that you are sending to.

#!/bin/sh

HOST=$(hostname -f)' 25'
CMD1='mail from: source@from.com'
CMD2='rcpt to: destination@goingto.com'
CMD3='DATA'
CMD4='basic text here'
CMD5="."
CMD6="quit"
(
echo open "$HOST"
sleep 2
echo "$CMD1"
echo "$CMD2"
echo "$CMD3"
echo "$CMD4"
echo "$CMD5"
echo "$CMD6"
sleep 2
echo "exit"
) | telnet

An Alternative Way To Send Email
Another way to do this is with Python; to learn how to use Python and not install anything else, see this external posting.