How Do I Write a Script to Test if a File Exists?

Problem scenario
You want a script to test if a file is in a specific location or not. You are using Linux. What should you do?

Solution
Use this script (but modify "/path/to/file" to be the path and name of the file you are searching for):

if [ -f "/path/to/file" ]
then
echo "file exists"
else
echo "file does not exist"
fi

How Do You Troubleshoot the ActiveMQ Build Failure “No plugin found for prefix ‘activemq-perf'”?

Problem scenario
You run this command:

sudo /opt/maven/bin/mvn activemq-perf:broker -Durl=broker:tcp://localhost:61616

You get this result:

[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 kB at 17 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (20 kB at 25 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.815 s
[INFO] Finished at: 2020-04-28T15:33:05Z
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'activemq-perf' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/root/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

What should you do?

Solution
Change directories to where the correct pom.xml file is. You could try this command:

sudo find / -name pom.xml

Here is the content of a pom.xml file that could work:

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.acme</groupId>
  <artifactId>run-amq</artifactId>
  <version>1.0-SNAPSHOT</version>
  <build>
    <plugins>
      <plugin>
    <groupId>org.apache.activemq.tooling</groupId>
    <artifactId>activemq-perf-maven-plugin</artifactId>
    <version>5.15.12</version>
      </plugin>
    </plugins>
  </build>
</project>

For future reference, here is a potential directory of the correct pom.xml file: /usr/local/apache-activemq/activemq-tooling/

How Do You Make an Indefinite Linux Command Go to the Background So That You Have Another Prompt?

Problem scenario
You want a non-terminating (or hanging) Linux command that never finishes to go to the background. You want to use the next command line prompt. The process starts from a command you issue at the command line. How do you do you get to the next prompt?

Solution

  1. This will suspend the process momentarily. Hold control and tap "z." Ctrl-z
  1. The above command will result in something like this:
    [555]+ Stopped python3 goodprogram.py

Craft a command like this, but replace 555 with the integer in the output of the command above:

bg 555
# Normally the value will be "1" -- not "555"

How Do You Get WordPress Preview Postings to Show “>> Read more…”?

Problem scenario
You are using WordPress to host your website. Some post previews show a hyperlink ">> Read more…" but others have no hyperlink. Some post previews (e.g., when you search the website for a pattern) are not updating. Older versions of the post are previewing. How do you get the ">> Read more…" hyperlink to show in the preview and how do you get the post to be up-to-date?

Possible Solution
Try copying the content of the old posting and posting it again. With new postings we cannot reproduce the problem.

What Do You Do when Your Internet Speed Is Slow?

Problem scenario
You are at home and your internet is slow. What should you do?

Possible solution #1
Reboot the cable router and any intermediate routers (i.e., any network device such as an IDS or firewall).

Possible solution #2
Log into your router's interface to view the connected devices. To do this, find the default gateway IP address of your computer. If you are using a Windows machine, hold the Windows key, tap the "r" key, then type: cmd

Then type ipconfig and press enter.

Open a web browser and go to this IP address. Enter credentials. Is there a networked or wireless device you do not recognize? Maybe there is a tablet computer or cell phone connected to your router.

Possible solution #3
Reboot your computer.

Possible solution #4
Go here to verify your bandwidth speed: https://www.speedtest.net/

How Do You Find Words That Match a Pattern and Not the Line with Bash?

Problem
You want to search a file for words that include a given pattern. You want to use grep to return the word that matches a pattern, and you do not want to return the entire line that matches a pattern. You want to return the exact word without the leading space or trailing space. What do you do?

Solution
Try this command:

cat foobar.txt | tr "//" "\n" | grep "coolpattern"

The above, specifically the tr command and flags, will introduce new lines for every space. You may need to pipe the output to an awk (e.g., | awk '{print $2}' ).

How Do You Troubleshoot the Adaware Antivirus Problem of “Definitions could not be updated”?

Problem scenario
You are using Adaware Antivirus. You try to download the latest definitions, but you get this error message: "Definitions could not be updated Something prevented the definitions from updating. Please try again at a later time."

How do you update Adaware Antivirus?

Solution
Try a different internet connection. Some public WiFi spots may block certain ports. VPN tunnels may not help solve the problem. A cell phone's hotspot (e.g., slinging internet service) may produce a better result.

How Do You Change the Time Zone in a Horde Email Account?

Problem scenario
Using a web-based email that is powered by Horde Mail (e.g., version 5), how do you change the time zone?

Solution

  1. Log in
  2. Click the gear symbol, go Preferences -> Global Preferences -> Locale and Time
  3. Change the time zone to your desired preference.

How Do You Find the Underlying Component in AWS for a Given URL Endpoint?

Problem scenario
You have been given a URL endpoint that is supported by some AWS service or services. How do you find out what the underlying service is?

Solution

  1. Determine the IP address. Ping the hostname. If you have a URL like this, https://acme.com/path/to/file.html, extract the domain name; you can deduce it is acme in the example. Open a command terminal and ping acme.
  2. Now that you have the IP address go to AWS console. Go to EC2 -> Instances and search for the IP address. If you cannot find it there, go to Reserved Instances, Spot Instances and finally Network Interfaces. Eventually you should find it.
  3. If you still have not found it, from a command prompt use "nslookup x.x.x.x" where x.x.x.x is the IP address. This may give you a clue of what to look for.