How Do You Use the $# Builtin Linux Variable?

Problem scenario
You want to test the $# built-in Linux variable. Every time you use it, it seems to return "0." How do you see the number of arguments in the most recent command?

Solution
Create a bash script with the following lines "echo... to fi":

echo "This script helps you learn about built-in variables in Linux."
if [ $# -eq 1 ]
   then
       echo "one argument was entered"
   else
       echo $# "arguments were entered."
fi

Run this script like this three times (with passing arguments in the last two):

bash coolscript.sh
bash coolscript.sh foo
bash coolscript.sh foo bar

# The output of the above three commands should demonstrate that $# keeps track of the number of arguments that were entered.

Why Can’t You Find the Linux Process for Apache Web Service That Appears to Be Running?

Problem scenario
You think the Apache web server is running.  You can see the web page from a web browser or your coworkers tell you that it is running.  You are not 100% sure however.  You want to see the Linux pid (process ID) for Apache web service that is running.  You run this:

ps -ef | grep httpd

You do not see any services running.  But you think that the Apache web service is in fact running.  Can Apache web service be running without an httpd process?

Solution
Run this:

ps -ef | grep apache

In Ubuntu Linux, Apache web server does not run with the httpd process.  It runs with a process with the string "apache".

If you still do not see an apache process running, it could be running in Docker.  Perhaps the web server you see is from a different server.  Sometimes with NAT or containers, IP addresses can become confused.

How Do You Upload Code to a GitLab Project from a Server That Does Not Have a Desktop UI?

Problem scenario
You have a Linux server with the command prompt but no GUI.  A separate server hosts GitLab.  How do you configure the first character-based server to use GitLab?

Solution
This assumes that you have deployed GitLab; if you need directions for this, see this posting.  This assumes that you have created a project in GitLab.  If you need directions for this, see this posting.

1.a.  From the web UI of the GitLab server, obtain the repository URL for the project.  It will look something like this:

git@goodserver/my-contint-project.git

If you cannot readily find this repository URL, you can log into the web UI of GitLab, go to Projects or "Projects" -> "Your projects".  Click on the project you want.  In the middle top of the screen there should be a field in between a "Fork"  button and an icon of a cloud/download button.  It will say "SSH" or "HTTP". Copy this string.  

1.b.  Go to the backend of the GitLab server.  Once you are at the character terminal, find the project on the backend.  To do this search for name of your .git file with a command like this:
sudo find / -name my-contint-project.git # but substitute the "my-contint-project.git" with the name of your git file (as the name should have been deteremined in step 5.a).

1.c.  Make a note of the full directory path found in step 1.b.

2.a.  Remain logged into the GitLab web UI.

2.b.  In the web UI for GitLab, click on the Project that has the repository you want (unless you are still at the "Details" screen where the Project's SSH or HTTP URL is visible).

2.c.  On the left click on "Settings".

2.d.  Click on "Repository" under "Settings."  

2.e.  Click on the "Expand" button for "Deploy Keys".

2.f.  Provide an arbitrary phrase in the "Title" field.

2.g.  Consider which server and which user will upload code to this GitLab project.  Go to that server and log in as that user even if it is a local user to that server.  Find the content of the id_rsa.pub file for this user (e.g., /home/jdoe/.ssh/id_rsa.pub).  If no id_rsa.pub file exists yet, go to the backend of the Linux server, log in as jdoe (or the user of your choice), run 'ssh-keygen -t rsa -P ""' and press enter to the next prompt.

Copy the contents of the id_rsa.pub file for this user on the server that will connect to the GitLab server and upload code to the GitLab project that you just created.  For the "Key" field input that is on the GUI of the GitLab server after step 2.f., paste the content of the id_rsa.pub file.

2.h.  Check the option for "Write access allowed"

2.i.  Click the green "Add key" button.

3.a.  From the server you want to upload code from, go to the Linux command prompt.  Log in as the user you want to upload  code as (e.g., jdoe).

3.b.  Verify git is installed (run "git --version").  Install it if necessary ("sudo apt-get -y install git" for a Debian distribution or "sudo yum -y install git" for a RedHat distribution).

3.c.  Draft a command like the one below (with "git clone" preceding the URL constructor obtained in step 1.a. above).    

git clone git@"<GitLabFQDN>":"<pathNotedin1.c>"/nameOfRepo.git

Substitute "<GitLabFQDN>" with either the FQDN of the GitLab server or the IP address.  Replace "<pathNotedin1.c>" with the  path you obtained in step 1.c above.  Substitute "nameOfRepo.git" with the name of the repository found in step 1.a.

Run this drafted command after you did the substitutions.

You may be prompted if you want to continue.  Choose "yes" with no quotes.  If you run the command above and you are prompted for a password, then the keys were probably not properly loaded to the GitLab GUI.  It is inadvisable, but you can continue with the git user.  If you do you may want to change the git user's password.  There are other ways of circumventing this problem (and this is extremely inadvisable to change the git user's password on the back end of the GitLab server because there are supported methods of using git commands). If you can change the git user's password (e.g, you are implementing a proof of concept or experimenting for the sake of learning with no sensitive data on a temporary server), log into the backend of the GitLab server.  Run this:  sudo passwd git

3.d. On the non-GitLab server, use this command:  cd nameOfRepo # where "nameOfRepo" is the name of the repository you just clones.  

3.e.  Create a file. For this example we'll use "fun.sh" with the content of these two lines:

var1=$(date)
echo $var1

3.f.  Run this command:  git add .

3.g.  Run this command but replace "jdoe" with the username that will interact with the GitLab project:  git config --global user.name "jdoe"

3.h.  Run this command:  git commit -m "Added a basic file."

3.i.  Run this command: git push origin master

Now you have added a file to the GitLab project.  Now you can add more files to the GitLab project via the Git command line.

How Do You Install MariaDB and Start the MariaDB Service in an Ubuntu-Based Docker Container?

Problem scenario
In an Ubuntu-based Docker container, how do you install MariaDB and start the MariaDB service?

Solution
Run these commands:

sudo apt-get -y update
sudo apt-get -y install vim
sudo apt-get install mariadb-server
sudo service mysql start

What and when Was The First Reference to Cloud Automation Operations?

Question
What and when was the first reference to cloud automation operations?

Answer
The cloud (e.g., the SaaS model or public cloud offerings) allow for new types of automation in computing.  Before electricity existed, pneumatic and hydraulic automations were among the oldest automations in history.  The only man-made clouds back then were smoke or steam clouds.

Homer's Iliad refers to cloud automation.  This appears to the be earliest use of such an idea (a gate), possibly made of water moisture such as a cloud, would open without any intervention.  The Iliad is believed to have been composed in the mid 750s BCE (Scientific American).  The ancient story describes automation in two different passages. 

"Observe the freedom of the imagery by which the gate, though said to be a cloud in 751, is made to creak." (Homer, The Iliad, book 5 line 749).

As of 2018 we do not think that tripods are relevant to cloud automation operations.  However The Iliad refers to "automatically travelling tripods." (Homer, The Iliad, book 18 line 376).  Pneumatic, hydraulic and supernatural automation could have involved clouds in oral history passed down as folklore in ancient times.  But we know of no record related to automated cloud operations before The Iliad was written.

Speaking of ancient operations related to computers, the world's largest undocumented computer is Stonehenge (according to page 163 of The Mythical Man-Month).

If you want to learn more about when non-cloud automation became an important concept to business outside of just cloud automation, see this posting.

In the Context of Nginx, What Is the Difference between the default.conf and nginx.conf Files?

Question
In the Context of Nginx, What Is the Difference between the default.conf and nginx.conf Files?

Answer
For general Nginx purposes, the nginx.conf file specifies the location of the Nginx logs and the names of the log files themselves.  

For general Nginx purposes, the default.conf handles many more configuration items than nginx.conf.   The default.conf file will allow you to configure a non-standard port (other than port 80) and specifies if Nginx will act as a load balancer or a web server.  If you choose to configure the Nginx deployment as an HTTP load balancer (distributing incoming connections to backend web servers), this default.conf file will allow you to configure how the traffic is distributed.  If you configure Nginx to be a web server, the location of the index.html file can be configured with default.conf.

How Do You Troubleshoot the Shell/Bash Script Error “syntax error near unexpected token”?

Problem scenario
You are trying to run a bash/shell script but you get an error message that is difficult to troubleshoot.  It looks something like this:

myscript.sh: line 4: syntax error near unexpected token `curl'
myscript.sh: line 4: `curl 'http://10.10.0.1' '

You thoroughly analyzed the line of the script that is called out in the error.  What is the root cause?

Solution
Did you define a function in the script?  The true problem may not be on the line that is called out in the error message.  If you defined a function like this "coolfunction{", this will cause the above problem.  The error message is misleading.  You need a space after the text "coolfunction" but before the opening brace "{".

How Do You Return Basic Messages from a SQL Query to a PHP Web Page When Using LAPP?

Problem scenario
You have deployed the LAPP stack. You want a basic and meaningful message to be presented to a user of the web application after a SQL command has been run.  Currently a user can click on buttons to run SQL commands behind the scenes.  Messages that are returned to the user may be meaningless like "Resource id #4" or "Resource id #5."  You want to augment the functionality so at least a rudimentary message (with some meaning) is returned to the user.  This way he/she will know if the query was successful or not.  How do you do this?

Solution
Assuming that you are invoking SQL commands with the pg_query command (see this link to deploy the LAPP stack), assign the output to a variable like this:

$varcomplete = pg_query($query);

Then add these two lines of code to your PHP page that is displayed after the user clicks the button to invoke a SQL command:

if ($varcomplete != '') {$varcomplete = "The query was successful";}
else {$varcomplete = "WARNING.  The query failed!!!";}

How Do You Deal with An “hwloc library not found” Error?

Problem scenario
You are trying to install Snort on Ubuntu.  You have installed hwloc (because you know the command hwloc-info works).  But when you try to run a configure script (e.g., configure_cmake.sh), you get this error:

"-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE)
CMake Error at cmake/FindHWLOC.cmake:6 (message):

        ERROR! hwloc library not found.

        Get it from https://www.open-mpi.org/projects/hwloc/

Call Stack (most recent call first):
  cmake/include_libraries.cmake:6 (find_package)
  CMakeLists.txt:18 (include)"

How do you troubleshoot this "Could not find PkgConfig: Missing:" error?

Solution
Install several packages with the following command:

sudo apt-get -y install libxext-dev libpng-dev libimlib2-dev libglew-dev libxrender-dev libxrandr-dev libglm-dev

# If one or two of the above is not found, do not be alarmed.  The above command may still solve the problem.

What is an Azure Function?

Updated 1/4/19

Question

You have heard of Azure's Serverless Function Apps.  What are they and what do they do?

Answer
A Serverless Function App is a PaaS solution.  As of 1/4/19 they support .NET or JavaScript code as if the code was run on a Windows environment.  They will eventually support Java/Linux.

You can run a program without a server using Azure.  It could potentially be accessible on the web or through other connectors to different Azure servers.  You do not need to be concerned about the systems administration on the back-end. See this posting if you want to use an Azure Function.