How Do You Troubleshoot the C Program Error “error: expected ‘;’ before string constant”?

Problem scenario
You try to compile a program with "gcc nameofprog.cc".  You get this output: "foobar.cc.:55:error: expected ';' before string constant"

What do you do to compile your program?

Solution
Go to line 55 of foobar.cc.  If there is a printf command, be sure that the thing to be printed is surrounded by parentheses.  Here is an example of a line that will cause the problem:
   printf "This is a test";

Here is an example of a printf command with proper syntax:
   printf ("This is a test");

How Do You Log onto a Free WiFi Network When There Is a “Internet not available” Error?

Problem scenario
You try connect via your wireless router to a WiFi network (e.g., at a restaurant, hotel, or public library).  You open a web browser because you were told you would be prompted with a splash screen.  On this page you would agree to the terms of service and/or enter a password.  You are not seeing this web page.  You try different URLs (e.g., www.yahoo.com, www.google.com).  You are never prompted for a username or password.

Firefox may show something like this: "Hmm. We’re having trouble finding that site."

Chrome may show something like this: "There is no Internet connection...DNS_PROBE_FINISHED_NO_INTERNET"

The Wireless Network Connection status shows you do not have internet access.  You cannot ping 8.8.8.8 from a command prompt either.  There is no evidence you are connected to the network.  You appear to be connected to the WiFi network itself.  What should you do to gain access  to the internet?

Solution(s)
Possible solution #1

Go to an IP address (with numbers) in a web browser and NOT a regular URL with letters.  Any IP address should work (e.g., 5.5.5.5).  This may resolve to the intended entrance webpage.

Possible solution #2  
Try a different web browser.

Possible solution #3
Try a different machine (e.g., a smart phone, tablet, or PC).

Possible solution #4
Reboot the machine.

Possible solution #5
Do you have a software firewall or security application with strict security settings?  This could be the cause of the problem.

Possible solution #6
Is your wireless network interface card configured to work with an internal DNS?  If there was special configuration done on your NIC, it may not be ready for a regular, public WiFi.

How Do You Troubleshoot the C Program Error “warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]”?

Problem scenario
You try to compile a program with "gcc nameofprog.cc".  You get this output:

"warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]"

What do you do to compile your program?

Solution
The program may still compile and run.  Look for the a.out file to be created.  It may be a working C program.  Just run it like this:  ./a.out

To get rid of the error, which is recommended as future C compilers may not be so forgiving, do the following.  First find the line number throwing the error.  The compilation error should have looked like this:

foobar.cc:15...warning: deprecated...

That means line 15 of the program named foobar.cc is causing the problem.  Line 15 will look something like this:

char* other = "coolphrase";

Rewrite it to be like this:

char const * other = "coolphrase";

Why Does the Repoquery Command Return Incorrect Information When the %{Size:M} Flag Is Used?

Problem scenario
You ran this command:  sudo repoquery openssl* --qf "%{name} %{size:m}"

You saw the following:

openssl 492 M
openssl-devel 1542 M
openssl-devel 1542 M
openssl-libs 991 M
openssl-libs 1221 M
openssl-perl 70.3 M
openssl-pkcs11 54.3 M
openssl-static 1068 M
openssl-static 1268 M
openssl098e 803 M
openssl098e 793 M

You know that the openssl packages are not this size.

The command "repoquery --version" returns this: "Repoquery version 0.0.11"

What should you do about the incorrect sizes of the packages you check with the repoquery command?  Or why do RPM packages look to be so big?

Solution
Use this command instead:

sudo repoquery openssl* --qf "%{name} %{size:h}"

You may want to use "yum info" if you do not trust openssl.

sudo yum info openssl*

Root cause
We suspect this is a bug.  The numeric values and lowercase "k" and uppercase "M" seem accurate with the ":h" flag and our cross-reference with the "yum info" command's results.  Here is an example of the output of the above repoquery command but with the ":h" flag:

[jdoe@goodserver ~]$ sudo repoquery openssl* --qf "%{name} %{size:h}"
openssl 492 k
openssl-devel 1.5 M
openssl-devel 1.5 M
openssl-libs 991 k
openssl-libs 1.2 M
openssl-perl 70 k
openssl-pkcs11 54 k
openssl-static 1.0 M
openssl-static 1.2 M
openssl098e 803 k
openssl098e 793 k

Additionally the man page of the repoquery command had this output:

"BUGS
       There  are  of  course  no bugs, but should you find any, you should first consult the FAQ section on http://yum.baseurl.org/wiki/Faq and if unsuccessful in finding a resolution contact the mailing list: yum-devel@lists.baseurl.org.  

To file a bug use  http://bugzilla.redhat.com  for  Fedora/RHEL/Centos  related bugs and http://yum.baseurl.org/report for all other bugs.

Panu Matilainen                                                           17 October 2005  "

We think that in 2018 we have discovered a bug.

Is It Acceptable to Store Configuration Files in Git, Subversion, CVS or Another Code Versioning Tool?

Problem scenario
You like the backup feature of a code versioning tool for potentially restoring files in a disaster recovery situation.  You want to store complete code bases including necessary configuration files in such a repository.  

This reputable link (https://www.cyberciti.biz/tips/my-10-unix-command-line-mistakes.html) says to use code versioning tools to store configuration files.  However this different reputable link says to not use code versioning tools to store configuration files.  Can you store .ini and other configuration files in a version control system?

Solution
According to the 12 Factor App rules, "A litmus test for whether an app has all config correctly factored out of the code is whether the codebase could be made open source at any moment, without compromising any credentials."

Based on a recommendation by SANS.org, we recommend not using Git for configuration files if they have a username and password.  Non-code files that store parameters and other configuration information can be stored in a code versioning repository.  We do not recommend such files that include credentials or sensitive information.  In other words, there are many exceptions to the rule "do not store configuration files in code versioning systems."  For disaster recovery or rolling back changes, you will want to have all the files that you need to get your software to work again.  You may want to include a file in a repository such as a README.txt that will direct the user to where the sensitive parameters and credentials are to be found.

How Do You Access the Networking Port of a Docker Container When There Appears to Be No Port Mapping, Just a Single Port Exposed by Itself?

Problem scenario
You run "docker ps -a" and see values in the PORTS column.  You see values such as these for two separate containers:

Container 1 has this:  0.0.0.0:32775->5000/tcp

Container 2 has this:  5731/tcp

You cannot reach the containers that have no "->" symbol in them via web browsers or other network connectivity tools.  You can reach those containers with the "->" symbol in the PORTS value.  What is wrong with the Docker containers with only one TCP port and not "->" syntax?

Solution
Those containers with no "->" mapping symbol in the PORTS value in the results of a "docker ps -a" command were potentially created without a necessary flag.  The "-P" option may be enough to get them to work properly.

For creating a container with a TCP port that will be exposed, use this command (with a known working Docker image):

docker create -it -P <image ID>

Alternatively you can use the "docker run" command to create and start a Docker container.  Here is the syntax for doing that with a known good image to create a container with a TCP port that will be exposed:

docker run -d -P <image ID>

How Do You Use Terraform to Create AWS Servers?

Problem scenario
You want to use Terraform to deploy EC-2 instances (VMs in AWS).  How do you do this?

Solution
These directions can work on a Linux server in your enterprise, a Linux server in Azure or a Linux server in AWS.

1.  Install Terraform.  See this link if you do not know how.

2.  Create a file like this called contint.tf with this as the content:

provider "aws" {
  access_key = "accessKeyHere"
  secret_key = "secretKeyHere"
  region     = "us-east-2"
}

resource "aws_instance" "example" {
  ami           = "ami-0b1e356e"
  instance_type = "t2.micro"
}

3.  Replace accessKeyHere with your AWS account's access key.  Replace secretKeyHere with your AWS account's secret key.  (You may also change the Amazon Machine ID if you desire.)

To find the AWS Access Key ID and AWS Secret Access Key, in the AWS console, click on your name in the upper right hand corner. Click on "My Security Credentials."  Click "Create New Access Key."  Then click "Show Access Key."   

Save the changes to the .tf file.

4.  From the directory with the .tf file, run these commands one at a time:

terraform init
terraform apply

5.  You are done.  The above steps will create an server (EC2 instance) in the "Ohio" region (also known as the us-east-2 region).  After the server is created you can create another server and delete the one you just created by changing the word "example" of basic.tf, then running the command "terraform apply" with no quotes.  Invoking "terraform apply" in a directory with a .tf file that is the same except the word "example" will do two things: delete the server that was created and create a new one.  If you want to delete the AWS server, you can run this command:

terraform destroy

# The above command will destroy terraform-provisioned infrastructure.

How Do You Deploy Artifactory in a Docker Container?

Problem scenario
You want to install and configure Artifactory in a Docker container on Linux.  How do you do this?

Solution
Prerequisites
i.  You must have Docker installed.  If you need assistance, click on the link for your distribution of Linux:

ii.  You must have Docker compose installed.  If you need assistance, see this posting.

Procedures

1.  Create a script in /tmp/ called artdock.sh with the content found in this file.

2.  Run the script like this: sudo bash /tmp/artdock.sh

3.  Open a web browser and go to the external IP address of the server (e.g., Docker host).  (To find this IP address from the back-end, run "curl icanhazip.com").  

4.  When looking at the web browser, close the initial pop up window after it loads.  To login, use the default username and password of "admin" and "password".

How Do You Install Docker on Debian 9 in GCP?

Problem scenario
You are running Debian 9 in GCP.  You want to install Docker on this server.  What should you do?

Solution
1.  Create a script in /tmp/ call installer.sh with the following lines of content:

#!/bin/bash
apt-get -y update
apt-get install -y apt-transport-https ca-certificates wget software-properties-common
wget https://download.docker.com/linux/debian/gpg
apt-key add gpg
echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee -a /etc/apt/sources.list.d/docker.list
apt-get -y update
apt-cache policy docker-ce
apt-get -y install docker-ce

2.  Run this command:  sudo bash /tmp/installer.sh

How Do You Install Redis on an Ubuntu 16.x or an 18.x Server in AWS?

Updated 12/26/18

Problem scenario

You want to deploy (install and configure) Redis (an in-memory data store) to an Ubuntu 16.x or an 18.x server.  What do you do?

Solution
These directions were based on this external posting as they appeared on 3/25/18.  

1.  Install some dependencies with these two commands:

sudo apt-get -y update
sudo apt-get -y install build-essential tcl

2.  Download the source media with this command:
curl http://download.redis.io/redis-stable.tar.gz > /tmp/redis-stable.tar.gz

3.  Install Redis with these commands:

sudo cp /tmp/redis-stable.tar.gz /opt/redis-stable.tar.gz
cd /opt/
sudo tar xzvf redis-stable.tar.gz
cd redis-stable
sudo make
sudo make test 
sudo make install

4.a.  Configure Redis with these commands: 

sudo mkdir /etc/redis
sudo cp /opt/redis-stable/redis.conf /etc/redis
sudo vi /etc/redis/redis.conf  
# find the uncommented "supervised" stanza and change the word "no" to "systemd"

4.b.  Configure Redis by creating a redis.service file.

sudo vi /etc/systemd/system/redis.service  # To create this file

# Insert these lines below to include "[Unit]" (as the first line) and 

"WantedBy=multi-user.target" (as the last line):

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

5.  Run these four commands to create the proper user, directory, and permissions settings:

sudo adduser --system --group --no-create-home redis
sudo mkdir /var/lib/redis
sudo chown redis:redis /var/lib/redis
sudo chmod 770 /var/lib/redis

6.  Run these two commands to start up Redis:

sudo systemctl start redis
sudo systemctl status redis

7.  Verify the installation with this command:  redis-server --version