How Can a Bash Variable Be a String with a Multi-word Linux Command with a Space in It That Can Be Executed Independently and Correctly?

Problem scenario
You have a variable in a Bash script that helps you compose a new Bash command.  You want to create a complex and dynamic Bash command.  This variable includes one or more spaces in it.

You can echo the commands and verify that these are valid Linux commands.  You run them and they test out.  But to run automatically in a script, you are finding that it can be difficult.  What can be done to get the script to run successfully with having spaces in the commands?

Solution
Have the script create a new [disposable] script with the correct commands appended into it.  Have that disposable script be run.  That disposable script can then be deleted.

Here is an example of doing complex sed commands with /etc/ssh/sshd_config:

var1=65  # You could introduce logic to have a more dynamic line number assignment (e.g., grep -n)
var2=91  # You could introduce logic to have a more dynamic line number assignment (e.g., grep -n)

comm1="sed -i \""$var1"s/KererosAuthentication no/KerberosAuthentication yes/\" /etc/ssh/sshd_config"

echo $comm1 >> /tmp/intermediate.sh  # this will create a temporary script

comm2="sed -i \""$var2"s/X11UseLocalhost no/X11UseLocalhost yes/\" /etc/ssh/sshd_config"

echo $comm2 >> /tmp/intermediate.sh

bash /tmp/intermediate.sh
rm /tmp/intermediate.sh   # delete this temporary script

How Do You Troubleshoot the Message “error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory”?

Problem scenario
You are using a Red Hat derivative of Linux (e.g., CentOS/RHEL/Fedora).  When trying to run a MongoDB command you receive this message: "error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory"

What should you do?

Solution
Get different installation media.  If you try to install a .tgz file for Ubuntu on CentOS/RHEL/Fedora, you will get this message.  The solution is to get new installation media.

How Do You Troubleshoot the Python Error “NameError: name is not defined” When Using Boto3?

Problem scenario
You are running a Python program with Boto and you get an error like this:

  " aws_access_key_id=AKIAJfoobar9999, NameError: name 'AKIAfoobar9999' is not defined"

What should you do?

Solution
Put single quotes around the aws_access_key_id value.

What Does the “git branch” Command Do?

Problem scenario
You have seen "git branch" and heard of branching strategies.  What does "git branch" actually do?  How can you use "git branch"?

Solution
In the context of version control or configuration management, branching is a fork of a codebase. 
(Forking is the creation of an independent copy of a repository; a branch is the same except it is a copy of a repository within the same repository for the purpose of merging with the main or "trunk" branch. Forking usually involves publishing the repository. A branch will be available whereever its trunk is available. The repository may not be published.) A branch is a duplicate version of the Git repository that is created for testing, prototyping or developing. The "git branch" command allows you to list, create or delete branches of a Git repository.  To understand what a branch of a code base is, try this from inside a git repository:

git branch --list  # *

To create a branch, from inside a git repository, run a command such as this:

git branch fun4whatever  # *

To delete a branch, from inside a git repository, run a command such as this:

git branch -D fun4whatever # replace "fun4whatever" with the name of your git repository's branch.

*  To install git, run sudo apt-get -y install git for a Debian distribution or sudo yum -y install git for a RedHat distribution.

You may want to do this first if you do not have a git repository:

git clone https://github.com/ContinualIntegration/portfolio.git
cd portfolio

How Do You Install and Configure Grunt?

Problem scenario
You want to use Grunt the automation tool (https://gruntjs.com).  How do you install it and get it to work on Linux?

Solution
#1  If you are using CentOS, Red Hat Enterprise Linux, or Fedora, run these two commands:

sudo yum -y install nodejs npm  # *
sudo npm install -g grunt

If you are using Debian or Ubuntu Linux, run this command:  sudo apt-get -y install nodejs npm grunt  # *

* If you need assistance installing Node.js and npm on a different distribution of Linux, see this posting.

2.a. Run this commmand:  sudo npm init

2.b.  # Respond with whatever you think is best.  You can press enter to these nine prompts:

name: (jdoe)
version: (1.0.0)
description:
entry point:
test command:
git repository:
keywords:
author:
license:

2.c.  For the "Is this ok?" prompt, choose "yes".

3.  Run these three commands:
sudo npm install -g grunt-cli
sudo npm install grunt --save-dev
sudo npm install grunt-contrib-concat --save-dev

4.  Create a file called Gruntfile.js with this as the content (the top line starts with "module.exports..."):

module.exports = function(grunt) {
    //based on https://stackoverflow.com/questions/15703598/
    // Project configuration.
    grunt.initConfig({
        concat: {
            "options": { "separator": ";" },
            "build": {
                "src": ["js/contint1.js", "js/contint2.js"],
                "dest": "js/completeapp.js"
            }
        }
    });

    // Load required modules
    grunt.loadNpmTasks('grunt-contrib-concat');

    // Task definitions
    grunt.registerTask('default', ['concat']);
};

5.  Run the command: grunt

You should see this:

'Running "concat:build" (concat) task

Done.'

6.  You can use this command to see what version of Grunt is installed:  grunt -V

How Do You Install and Configure Gulp?

Problem scenario
You want to use Gulp the automation tool (https://gulpjs.com/).  How do you install it and get it to work on Linux (either a Debian distribution or a Red Hat distribution)?

Solution
1.  If you are using CentOS, Red Hat Enterprise Linux, or Fedora, run these two commands:

sudo yum -y install nodejs npm  # *
sudo npm install -g gulp

If you are using Debian or Ubuntu Linux, run this command:  sudo apt-get -y install nodejs npm gulp  # *

* If you need assistance installing Node.js and npm on a different distribution of Linux, see this posting.

2.a. Run this commmand:  sudo npm init

2.b.  # Respond with whatever you think is best.  You can press enter to these six prompts:

name: (jdoe)
version: (1.0.0)
git repository:
keywords:
author:
license:

2.c.  For the "Is this ok?" prompt, choose "yes".

3  Run this command:  sudo npm install --save-dev gulp

4.  Create a file called Gulpfile.js with this as the content (the top line starts with "var gulp..."):

var gulp = require('gulp');
gulp.task('default', function() {
  // place code for your default task here
});

5.  Run the command: gulp

You should see this:

[12:46:49] Using gulpfile ~/Gulpfile.js
[12:46:49] Starting 'default'...
[12:46:49] Finished 'default' after 125 µs

6.  You can use this command to see what version of Gulp is installed:  gulp -v

How Do You Use the screen Program in Linux?

Problem scenario
You would rather not create duplicate terminal windows in your Linux desktop or with PuTTy in Windows.  This may be an enforced security policy rather than a preference.  Some Linux systems only allow one log on session.  Perhaps you want the systems administrator to use the "who" or "w" command to see which users are logged in without seeing more than one session for your user.

How do you use the screen command to have different terminals simultaneously with the requirements above?

How do you allow a continually-streaming program wall or echo messages to the console while you have a separate session without a second log on session?

Solution
Use the screen utility.  It is extremely helpful with long-duration processes to manage different screens from one session.

1.  Optional step.  Run this command:  screen -list

2.  Enter this command:  screen

3.  Run commands as you desire.  To exit, use these two commands:  ctrl-a, ctrl-d

(Holding control tap "a" then holding control again tap "d".)

4.  Run commands from the original prompt.  You can use "screen -list" to view the different sessions.  You can create more than one screen session.  They will not register as new logon sessions on the Linux server.  If you want to return to a previous session, use this command (but replace 1234.gooserver with the left-most column value of the output resulting from a "screen list" command):

screen -r 1234.goodserver

How Do You Trace the Route of a Network Path from One Server to an IP address elsewhere on the Network?

Problem scenario
You want to see the path that network traffic takes from one server to another network endpoint.  How do you find the intermediate path from the server your are on to a reachable IP address?

Solution
Use a tracing utility.  If your server is running Windows, use tracert.  Here is an example of how to use it:  tracert 8.8.8.8

If your server is running Linux, use traceroute.  Here is an example of how to use it: traceroute 8.8.8.8

For comprehending the details of TCP/IP connectivity and identifying latency (e.g., pinpointing slowness), tracing utilities such as these can be very effective.

The underlying mechanism of both of these tracing utilities is the destination is attempted to be contacted with a series of network packets.  The first packet in the series has a TTL (time-to-live) setting of 1.  The second in the series has a 2.  The third has a three, and the subsequent packets are successively incremented.  When the destination is finally reached, the tracing utility stops sending packets.  

If you do not know how TTL packets work, read the following.  A TTL setting of one will allow the packet to traverse one hop toward the destination IP address.  A TTL setting of two will allow the packet to make two hops toward the destination IP address.  A packet's TTL value is decremented with each time it traverses a device (such as a router, switch, firewall or computer).  That is why a packet with a TTL setting of 1 can only make one hop.  The physical length of the cables supporting the packet or the duration of the packet's life in terms of time have no affect on a packet's TTL value.  

The starting TTL setting (integer value) is the maximum number of hops from the server to another discrete device (e.g., a router, a switch, a firewall, a routing computer) that the network packet can pass through.  Therefore a TTL setting of one will allow the packet to make one hop to the nearest router or switch, then stop.  In a tracing utility the second packet in the series will make two hops toward the destination IP address based on routing tables.  If you do a traceroute or tracert for the nearest network device, the first packet will arrive at its destination and the program will end.

For more information, about tracert, see this Microsoft link.  For more information about traceroute, see this link.

How Do You Add Files to a New Project in GitLab?

Problem scenario
You want to add files to a new project in GitLab.  You want to do this from the command prompt (not through the web UI).   How do you do this?

Solution
This assumes you have a new project created; if you do not know how, see this posting.  If you want to import a project, see this posting.

Procedures
1.  Make sure you have the regular git installed on your server.  (Installing GitLab does not necessarily install git.) Run this command to test it:  git --version

(Install git if the command was not recognized.)

2.  From the backend of the Linux server, run these commands but read the notes to the right of them before you run them as the commands are just drafts:

git config --global user.name "Administrator"
git config --global user.email "admin@continualintegration.com"  
 # change to email of your choice

git clone git@x.x.x.x:root/contint.git  # change x.x.x.x to the IP address of the GitLab server and change contint to the name of the project you just created
cd contint # change contint to the name of the project you just created
touch README.md
touch foobar.txt
git add .
git commit -m "added two new files"
git push -u origin master

3.  You have now uploaded files to a project in GitLab.