How Do You Troubleshoot a Bash Script Copied from the Internet?

You have one of the following two problems:

Problem scenario #1
Your GCP startup-script is not working. You do not know why. What should you do?

OR

Problem scenario #2
A bash script is not working. It stops executing after a certain line. There are few clues as to what is wrong.

Solution
Did you copy the script from a webpage?

…

How Do You Get the “Up” Arrow to Show a Previous Command in Linux?

Problem scenario
When you press the up arrow on the keyboard you see ” ^[[A”. You want to see the previous command that was entered. How do you enable history at the command line?

Solution
Root cause: The /etc/passwd file has an entry like this:

cooluser:x:1001:1002::/home/cooluser:

(This could be caused if you created the user quickly with a useradd command.)

Procedures

Run this command: sudo cat /etc/passwd | grep $(whoami)

Do you see a /bin/bash at the end?

…

How Do You Zero out a /var/log/mail File?

Problem scenario
You backed up /var/log/mail to a different file. You want the /var/log/mail file to start empty so you can review it without looking at old activity. What do you do?

Solution
Run these four commands:

sudo su –
cd /var/log
mail
exit

Now you /var/log/mail file will still exist and record activity as normal. It will not have anything in it before the time you ran the above “>

…

What Does “__” Mean in Python?

Problem scenario
You see two underscores or two underbars before a function in Python. What does this syntax signify?

Possible Solution #1
The answer is best explained by running this program once with no modification and a second time with a modification.

class ContintClass():
def __init__(self):
self.__completelyprivate = “1111111111”
self._semiprivate = “2222222”

foo = ContintClass()
#print(foo.__completelyprivate)

print(“Above is an attempt to print a completely private data member of an object”)

print(“Below is an attempt to print a semi-private data member of an object”)
print(foo._semiprivate)

Before you run the program the second time,

…

How Do You Get the ElasticSearch, LogStash or Kibana Service to Remain On?

Problem scenario
The elasticsearch, logstash or kibana services will start, but when you check the status, it does not remain on. It keeps stopping. You see the status as “failed.”

Solution
Possible Solution #1
Add more memory or swap space to the system. If you need assistance with either of these, see this posting.

…

Why is Your Python Programming Printing Duplicate Lines?

Problem scenario
You have a Python program with print statements. When you run the program, you get twice as many print statements as you expect. What could be wrong?

Possible Solution #1
Do not name the program re.py or string.py. When you name the program re.py and have an import re statement, Python may print every line it is supposed to print twice.

…