How Do You Delete a Directory on Linux Server That Is Not Easily Deleted?

Problem scenario
You are trying to remove a directory.  When you run a “sudo rm -rf” command you get this error:

rm: cannot remove ‘/path/to/’: Device or resource busy

When you run a “sudo umount /path/to/” command you get this error:

“umount.nfs: device is busy”

What should you do to eliminate the directory?

Solution
1. 

How Do You Use a Jenkins Pipeline with a Scripted Syntax?

Updated and re-tested on 9/24/19
Problem scenario
You read about what Jenkinsfiles are.  Coveros.com defines them as ‘Jenkinsfiles, using a domain specific language based on the Groovy programming language, are persistent files that model delivery pipelines “as code”, containing the complete set of encoded steps (steps, nodes, and stages) necessary to define the entire application life-cycle.’

You want to use a Scripted Pipeline in Jenkins (via a Jenkinsfile). 

How Do You Indent a Block of Lines in vi The Same Amount?

Problem scenario
You want several lines to be indented by four more spaces automatically.  You do not want to do it manually line-by-line.  How do you indent multiple lines uniformly with the same number of spaces (regardless if they are indented similarly or dissimilarly)?

Solution
1.  Open the file in vi.
2.  Enter this command and press enter afterwards (but replace “4” with the number of spaces you want in your indentation):    

How Do You Troubleshoot the Ansible Error “this task includes an undefined variable”?

Problem scenario
You are running an Ansible playbook, but you get the error “this task includes an undefined variable.”  Every variable seems to be defined.  What is wrong?

Possible solution #1
Do one of the variables rely on an index of server names?  If the playbook orchestrates something that responds to Ansible values on other servers and one server is not reachable, you could get this error. 

How Do You Clone a Git Repository when You Are Being Prompted for a Password and Do Not Know What It Is?

Problem scenario
You have a Git repository on one server.  You want to clone it to another server.  When you try to clone it, you are prompted for a password.  What do you do?

Solution
On the destination server, run this (where x.x.x.x is the IP address of the server with the Git repo):

git clone git@x.x.x.x:root/goodrepo.git

If you are prompted for a password,

How Do You Get awk to Use a Colon or a Semicolon as a Field Separator?

Problem scenario
You run a command such as this, with the goal of printing the number of occurrences of “foo”:

grep -icR foo * | awk ‘{fs=”:”; print $2}’

It does not do what you want it to do.  You want the field separator to be a colon.  It is not working.  How do you print the element after a “:” (colon) with an awk utility?

How Do You Set up AWS CloudFront?

Problem scenario
You want to test out a CDN in AWS.  What do you initially deploy CloudFront?

Solution

Prerequisite
This assumes that you have an S3 bucket with read permissions.  To do this, log into the Amazon S3 console and create a bucket.  Upload files and configure the permissions to grant read permissions to anyone.  

Procedures
AWS CloudFront has “Distributions.”  You want to create a CloudFront Distribution.

How Do You Use the MongoDB Command Line?

Problem scenario
You want to enter the MongoDB shell to enter commands interactively.  What do you do?

Solution
1.  Run this command:  /usr/bin/mongo

If the command is not found, do two things:
  a)  Run this: sudo find / -name mongo | grep bin
  b)  Run the mongo file found above (as an executable).

2.  From the prompt “>” enter a command such as this:

db

How Do You Troubleshoot the Logstash (or Elastic Stack) Error “logging.log4j.core.appender.RollingFileAppender”?

Problem scenario
You try to start Logstash but you get this error: “main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile: “

What should you do?

Solution
Do one of the two options below.

#1  Solution (rather simple, for a one-time fix)
Do not start the process with the root or some other regular user.