How Do You Troubleshoot a Bash Script with the Error “No such file or directory”?

Problem scenario
An "if" statement in Bash is throwing an error message "No such file or directory." What do you do?

Possible solution #1
Replace the parentheses around the arithmetical comparison with double parentheses. Instead of this:

if ( $numlines < 5); then

Use this:

if (( $numlines < 5)); then

Possible solution #2
Replace the "[]" with "(())".

Instead of this:

if [ $numlines < 5]; then

Use this:

if (( $numlines < 5)); then

How Do You Get Your Linux Email Server to Deliver Email Consistently?

Problem scenario
You quickly set up an email server on a virtual machine in a public cloud. Some emails from the server are being received but some are not being received. What could be wrong?

Solution
1. If you are using Postfix, check the files in these locations:

/var/spool/postfix/private/bounce
/var/spool/postfix/bounce
/usr/lib/postfix/bounce

2. Look at the file /var/log/mail for clues about what could be wrong. If it is being written to (that is, if there is mail activity), you may want to make a copy of the file and delete that copy when you are done. When examining the file with vi, use this command:
:set ignorecase
Then you can use the forward slash "/" to search for patterns (e.g., "return", "fail", or "undeliverable"). In our experience the word "rejected" is a good one to search for.

3. Check the hostname of the server to see if it has numbers. The email server's hostname can be alphanumeric. Is an IP address visible (e.g., AWS servers look like this: 172-3-56-91.us-west-2.compute.amazonaws.com) in the hostname? Some spam filters will identify this hostname as a "likely spam" problem. There is a points algorithm that some anti-spam filters use which can lead to non-delivery of email. This can be solved as easily as changing the hostname of the server. Modify the /etc/hostname file to have the new hostname you want. Update the /etc/hosts file and mail.cf files to reflect this new hostname (without four octets being divided by dashes). Reboot the server and then send an email.

Please do not use this to spam people. Send email responsibly!

Another Possible Solution
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 Install GitLab on a CentOS/RHEL/Fedora Server?

Problem scenario
You want to install GitLab on a Red Hat derivative of Linux. What should you do?

Solution
1. Get a CentOS/RHEL/Fedora Linux server with either 3.5 GB of RAM or at least 1.5 GB of RAM and 2 GB of virtual memory. If you need to add more memory (e.g., to an AWS EC-2 instance or a physical on-premise server), this posting can help you.

2. Run these commands from the backend of the Linux server:

yum install -y postfix 
service postfix start
chkconfig postfix on
lokkit -s http -s ssh
yum install -y curl openssh-server cronie

3. Create a file with this command: sudo vi /etc/yum.repos.d/gitlab-ce.repo
Use the content below:

[gitlab-ce]
name=gitlab-ce
baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/7/$basearch
repo_gpgcheck=1
gpgcheck=1
enabled=1
gpgkey=https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey
       https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey/gitlab-gitlab-ce-3D645A26AB9FBD22.pub.gpg
metadata_expire=300

4. Run these commands:

sudo yum -y makecache
sudo yum -y upgrade
sudo yum -y update
sudo yum -y install policycoreutils-python-utils

5. Run a modified version of command. Substitute x.x.x.x with the external IP address of your server or the URL you want to access via a web browser when the process is finished:

sudo EXTERNAL_URL="http://x.x.x.x" yum -y install gitlab-ce --nobest

6. Run this command: sudo gitlab-ctl reconfigure
If you see "Chef Client finished…" proceed to the next step. If you see "Chef Client failed…" then run this again: sudo gitlab-ctl reconfigure

7. Find a file, back it up, and modify it.
7.a. Run this command: sudo find / -name engine.rb | grep bcrypt
7.b. Back up the file that is found. (e.g., copy /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11/lib/bcrypt/engine.rb somewhere else)
7.c. Modify the file that is found. Replace line 57 which should look like this when you first find it:

__bc_crypt(secret.to_s, salt)

with this line:

__bc_crypt(secret.to_s, salt).gsub(/(\n|\x00).*/, '')

(This step was adapted from this posting.)

8. Reboot the server.

9. With a web browser go to the web UI over port 80. Click on "Register". You will be prompted to create a new password. Remember this password.

10. Log into the web UI.

How Do You Set up a Send-Only Email (Postfix) Server on a Linux SUSE AWS Instance?

Problem scenario
You have a monitoring tool on a Linux server that needs to send out emails upon certain events happening. You want to install and configure an email server. You need to send outbound emails, but you do not need to receive inbound emails. How do you configure Linux SUSE to be able to send out regular emails over the internet?

Solution
1. Ensure that the security group allows for outbound connectivity over port 25.
2. Log into the Linux SUSE server.
3. Run this command: hostname

4. Ensure that the hostname does not have numeric sequences like an IP address. For example, the hostname should not have something like this (note the hyphens): ip-172-31-1-1

It seems unusual, but it bears repeating: you may encounter problems if the alphanumeric hostname has numeric sequences -- such are a tell-tale sign of an IP address. We have had problems with sequences of numbers in the hostname. To change the hostname, you would modify /etc/hostname so it has the hostname you want. Make sure that the /etc/hosts file has a stanza with the internal IP address of the server and the hostname in /etc/hostname. Once these are changed you should reboot the server.

5. Find the internal IP address. It is usually in the FQDN of an AWS server. You could run this command (and ignore the /20 at the end of its output):

ip addr show | grep eth0 | grep inet | awk '{print $2}'

You'll need the result of the above command later.

6. Run this command to install Postfix: sudo zypper -n install postfix

7. Edit the /etc/postfix/main.cf file.

7.a. The /etc/postfix/main.cf should have lines like these at the very end (but replace contint.com with the FQDN of the server 10.10.10.10 with the internal IP address as found in steps 3 and 4 above).

inet_interfaces = localhost, 10.10.10.10
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain
myhostname = contint.com

7.b. In the /etc/postfix/main.cf, comment out the previous stanzas for inet_interfaces and myhostname in the file. Use the "#" (with no quotes) to do this. Save the changes.

8. If you have a DNS server so the FQDN resolves, skip this step. Otherwise update the /etc/hosts file to have an entry like this (where contint is the hostname in step 3 and where 10.10.10.10 is the internal IP address as found in step 4):

10.10.10.10 contint

9. Restart the postfix server. Run this command: sudo service postfix restart

10. Optional step. Test it. Type in the following but do these four things first to draft the commands specific to your environment: one, replace contint in the helo command with the plain hostname (the one that results from the "hostname" command); two, replace webmaster@contint.com with the sender's email address, or the one you want to appear as the sender; three, replace "goodperson@gyahoomail.com" with the destination email address, and four press enter after each line:

telnet 127.0.0.1 25
helo contint
mail from: webmaster@contint.com
rcpt to: goodperson@gyahoomail.com
DATA
This is just a test.
.
quit

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.

In Python How Is the List Function “remove” Different from “pop”?

Problem scenario
You want to know how remove is different from pop when manipulating a list in Python. What should you do?

Solution
Here are four facts which should help elucidate the differences.

  1. The remove keyword searches for a matching item in the list -- not by its indexed, integer value; then the first matching item is removed. (We tested it. You may want to see this external page.)
  2. Remove does not return a value.
  3. Pop removes an item based on its indexed, integer value.
  4. Pop returns the item removed.

Here are two programs which help display the the details of what is happening behind-the-scenes.

This program involves four function calls:

import cProfile
a = "z", "y", "x", "w", "v"
contintlist = list(a)
cProfile.run('contintlist.remove("z")')

# One function call is finding the matching element in the list.  The second is removing the first match.  

This program also involves four function calls:

import cProfile
a = 1, 2, 3, 4, 5
contintlist = list(a)
cProfile.run('contintlist.pop(3)')

# One function call is removing the item in the list.  The second is returning that item.

How Do You Troubleshoot the nmap Results “Host seems down” when the Other Server is Not Down?

Problem scenario
Two servers have a specific incoming port open between them. But when you try nmap to test the port, you get a message like this:

Starting Nmap 7.60 ( https://nmap.org ) at 2019-10-08 19:57 UTC
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 3.04 seconds

What should you do?

Possible solution #1
Try to use "sudo" before your nmap command. You can find that port 22 is open via SSH or with "sudo nmap -p 22 x.x.x.x" or with "nmap -Pn x.x.x.x" or with using SSH. Just using "nmap -p 22 x.x.x.x" can show that "Host seems down". To learn more about the differences with "sudo" see this posting.

Possible solution #2
Try internal or external IP addresses. Some security rules governing the endpoints (or devices) filter based on the originating IP address.

Possible solution #3
Double check the IP addresses; human error can make this symptom seem to appear. Use traceroute or tracert between the servers.

Possible solution #4
Have ICMP packets been turned off in the intermediate network devices? Try to use ping to see if it works. nmap results can show nothing, but ping may tell you something.

Possible solution #5
Configure security groups, network security groups, firewalls, routers, and/or IDSes between the endpoints. Incoming or outgoing ports can be filtered. Open more ports between the two hosts. If a firewall or security group is blocking some ports, this could happen. Surgically opening the port you are testing in an Amazon Security Group would not be sufficient to have nmap show it is open.

Possible solution #6
See this posting.

How Do You Get the /var/log/mail File to Start Over?

Problem scenario
You want to search for activity associated with a given email address. You do not want to examine historical records because you made a configuration change. How do you eliminate the old records of the file and start over?

Solution
1. Make a back up of the file. (The commands below will eliminate the original copy.)
2. Run these four commands:

sudo su - 
cd /var/log
mail
exit

How Do You Find out What Packages You Can Install That Are Related to a Certain Category when Using CentOS/RedHat/Fedora Linux?

Problem scenario
You want to find what Java packages are available on the configured repositories of the RedHat distribution of Linux server you are using. What do you do?

Solution
Run a command like this: sudo yum list available | grep -i java

# Replace "java" above with the package you want to learn more about from the available options.