In a Bash Script How Do You Assign a Variable a Value of a Complex Linux Expression?

Problem scenario:  You know how to assign variables in a Bash script. But how do you assign the output of a complex command such as this?

cat foo.txt | grep continual | grep integration | uniq

To push the output of some compound statement into a text file is simple.  Sometimes you want to redirect everything to a variable. How do you do this?

Solution:  Use $(expression)

For example:
varA=$(cat foo.txt | grep continual | grep integration | uniq)

Remember that there cannot be spaces around the equal sign.  Later call varA like this to evaluate it for its content: $varA

How Do You Configure Linux To Be Ready for Cloudera 5 (Hadoop)?

Two problem scenarios and solutions.

Problem scenario:
  You installed Cloudera 5 (Hadoop) on CentOS 7.2 for the first time. You tried to start the Cloudera database service. But you get an error that it failed.

You run this: systemctl status cloudera-scm-server-db.service

The results include this fragment:  "  ... Failed to start LSB: Cloudera SCM Server's Embedded DB."

How do you start the Cloudera DB service?

Solution
Disable SELinux. 

  • If you find the file /etc/sysconfig/selinux, modify it.  Replace "SELINUX=enforcing" with "SELINUX=disabled".  Reboot the Linux server.  
  • If you cannot find the file, e.g., you are on RHEL 7.3, find /etc/selinux/config and modify it.  Replace "SELINUX=enforcing" with "SELINUX=disabled".  Reboot the Linux server.  

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Problem scenario:  You installed Cloudera 5 (Hadoop) on Linux.  But you cannot reach the web UI from a regular Windows workstation from any port.  What should you do?

Solution
Shut off the firewall on the Linux server or reconfigure it.  You may want to research the consequences of this change before doing it.

How To Troubleshoot Mounting a File Share With The Error “mount: wrong fs type, bad option, bad superblock”?

Problem scenario:  You try to mount a file share with this command:
mount continualintegration.com:/export/path/to /mnt

You get this error:

" mount: wrong fs type, bad option, bad superblock on continualintegration.com:/export/path/to,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)
       In some cases useful info is found in syslog - try dmesg | tail"

Solution:

#1  Verify there is a space between the two arguments (continualintegration.com:/export/path/to and /mnt).

#2  This next step may install more packages than necessary.  But it should help eliminate the problem if you need a quick solution.

If you are running a Debian distribution of Linux, run this:

sudo apt-get install -y nfs-common cifs-utils nfs4-acl-tools nfs-utils

If you are running a RedHat distribution of Linux, run this:

sudo yum -y install nfs-common cifs-utils nfs4-acl-tools nfs-utils

If you are running a SUSE distribution of Linux, run this:

sudo zypper -n install nfs-common cifs-utils nfs4-acl-tools nfs-utils

How Do You See The Time Previous Commands Were Entered On A Linux Server?

Question:  How do you see the exact time when previous commands were entered on a Linux server when you use the "history" command?  

Background:  Linux by default logs the time and day when commands were issued.  (There is a limit to the number of previous commands that stay logged.)  The timestamps by default are not visible.

Solution:  For the session, until you log out, this will work:

HISTTIMEFORMAT="%d/%m/%y %T "

If you permanently want to see the timestamps associated with the commands entered even after a reboot, you execute this command once:

echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile ; source ~/.bash_profile

The above works on RedHat, SUSE, and Ubuntu.

Puppet Needs To Use a Windows Network File Share: How Is This Done Consistently?

Problem Scenario:  You are using Puppet Master on Linux and Puppet Agent on Windows servers.  The manifest attempts to copy to or from a Windows network file share, but you are getting an error about the network path not existing.  The network file share has permissions that are open to Everyone.  What do you do?

Solution:  Puppet Agent will run PowerShell commands under the security context of the user who runs the "puppet agent -t -d" command.  If no one is logged in, the local system user will be the user whose security context is running the commands.  For the first time that the network file share is used from the Windows server, it is sometimes necessary to use a command like this: 

net use \\fileShareServer /USER:continual integration

Replace "fileShareServer" with the hostname of the file share.  Any username and any password will work because the file share is open to Everyone.  Note that there is no closing backslash after the fileShareServer name.  So the Puppet manifest should look like this:

...
command => 'net use \\\fileShareServer /USER:continual integration; echo "this is the manifest command" > \\\fileShareServer'
...

Three backslashes in a manifest on Linux will translate to two backslashes on a Windows server.  The main idea is that the "net use" command needs to run one time for initial use (and any credentials will suffice).

How Do You Control The Order Of When Puppet Manifests Are Applied to a Puppet Agent?

Problem scenario:  One Puppet manifest relies on another manifest to work.  Trying to apply them at the same time is not working.  The "require" and "before" keywords only seem to work for packages, exec, and file resources.  What do you do to order the manifests to satisfy dependency requirements of other manifests?

Solution:  The relationship dependency can be solved by the order in which they are applied.   The keyword "import" has been deprecated and made obsolete in many versions of Puppet.  The keyword "include" in the existing manifests (either one) will not solve the ordering problem.

The solution is to create a third module with its own manifest and call the existing manifests in the desired order from top to bottom with the "include" key word.  We'll call the module "continual" for this example.  Here is its manifest (init.pp):

continual {
   include integration
   include specialty
   }

The above manifest for the "continual" module will apply the "integration" manifest first.  The "integration" manifest is the init.pp file in the manifests directory of the module named "integration."   In the example above "specialty" is a Puppet module that requires "integration" to have been applied.  The "specialty" module will be applied after the "integration" module.

This solution is modular in that the original respective modules can be completely separate and unmodified.  This composite manifest applies the component manifests in the order to solve the dependency problems.

How Do You Use a Text-Based Web Browser on RedHat Linux?

Background:  Text-based browsers are fast.  Operations can be scriptable and repeatable.

Question:  How Do You Use a Text-Based Web Browser on RedHat Linux?

Prerequisites:  You have access to the Internet and root access.

Solution:  As root, enter these two commands (where "#" is the command prompt).

# yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional
# yum -y install lynx

To test it out, run this:
lynx continualintegration.com

By default you will be prompted to accept cookies.  If privacy is a concern, this is a good thing.  Radio check buttons are toggled with the right arrow key.  This solution works on AWS instances of RedHat as long as you have access to the Internet.

Puppet IIS Module Troubleshooting

Update on 3/30/17:  The Puppet IIS module has been updated, and the problem below has been eliminated.

Problem scenario:  You want Puppet to install IIS.  You install the IIS module and find the README.md file has this Puppet DSL (as of 12/13/16):

class mywebsite {
  iis::manage_app_pool {'my_application_pool':
    enable_32_bit           => true,
    managed_runtime_version => 'v4.0',
  }
   iis::manage_site {'www.mysite.com':
    site_path     => 'C:\inetpub\wwwroot\mysite',
    site_id       => '10'
    port          => '80',
    ip_address    => '*',
    host_header   => 'www.mysite.com',
    app_pool      => 'my_application_pool'
  }
...

It is also found on https://forge.puppet.com/puppet/iis

Why is there no comma after site_id? 

Solution:  This appears to be a typo in the syntax.  Any line besides the last should have a comma after it.  The open source movement has numerous advantages.  However, sometimes the community has to keep after the discovery of errors to make things work.

How Do I Assign User Input from a Bash Script to a Variable?

Question
How Do I Assign User Input from a Bash Script to a Variable?

Answer
The script below will read in two variables.  One will be referred to as $remoteIP and the other will be referred to as $remotePort later in the script.  The "$" symbol will evaluate the variable so its value will participate in the expression (e.g., for echoing to the screen or manipulating for conditional logic) later in the script.

#!/bin/bash
echo "Enter the IP address you want to test"
read remoteIP

echo "Enter the port number you want to test"
read remotePort