Problem scenario
You want each line of a file to have a prefix or suffix attached. How do you print out this combination of a fixed string with each individual line of the file?
Solution
cat foobar.txt | awk '{ print "prefix" $1 "suffix" }'
A Technical I.T./DevOps Blog
Problem scenario
You want each line of a file to have a prefix or suffix attached. How do you print out this combination of a fixed string with each individual line of the file?
Solution
cat foobar.txt | awk '{ print "prefix" $1 "suffix" }'
Question
Normally when you use the man page, you just type man nameofcommand. But you have seen integer numbers between 1 and 9 (inclusive) between the "man" and the command's name. What do those numbers signify?
Answer
This legend was taken from "man man" on a Linux server:
1 Executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library calls (functions within program libraries)
4 Special files (usually found in /dev)
5 File formats and conventions eg /etc/passwd
6 Games
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
8 System administration commands (usually only for root)
9 Kernel routines [Non standard]
Problem scenario
You have a list in Python that you copy into another variable. You change the original list and the copied version changes. Why does the copied version get copied and what can you do to overcome this?
Solution
There is something called a "deep" copy and a "shallow" copy. This program will illustrate both the problem and the solution:
list_a = [3, 6, 7]
list_b = list_a
list_c = list_a[:]
list_a.append(4)
print(list_b)
print("list_b, a shallow copy, is above; list_a is below")
print(list_a)
print("a different copy of list_a is below")
print(list_c)
For more information, read the following links: StackOverflow.com and geeksforgeeks.com.
Problem scenario
You want to use the copy feature in Python. What do you do?
Solution
To see the different types of copying, use a mutable object such as a list. Here is an example:
import copy
var1 = [1, 2, 3, 4]
shallow_copy = var1
deep_copy = copy.deepcopy(var1)
var1.append(999999999999)
print()
print(shallow_copy)
print(" --- Shallow copy above and deep copy below ---.")
print(deep_copy)
For most (or perhaps all) intents and purposes, you cannot shallow copy a string. You can shallow copy a list or other mutable object. This is how you can use the .copy() feature with a string (but notice how the effect of deep copying takes place):
import copy
var1 = "a sample string"
shallow_copy = var1
deep_copy = copy.deepcopy(var1)
var1 = var1 + " some extra text added later on -----------------------------------------"
print()
print(shallow_copy)
print(" --- Shallow copy above and deep copy below ---.")
print(deep_copy)
If you cannot use the copy module (e.g., use "import copy") see this PoStInG: Why in Python Does a Variable Copy Get Changed when You Change Its Source?
Question
You were told to write a Python program in virtualenv (a layer of virtualization). Why are you being asked to do this?
Answer
Isolation of dependencies is one of the dozen factors in 12 Factor App. Using pip or pip3 on an entire Linux system to install packages for PyPI is inadvisable (according to page 32 of Expert Python Programming). This could install an older package that may have undesirable consequences. If you use virtualenv, you introduce a layer of virtualization to contain the effects of the package (according to page 360 of Expert Python Programming). The newer 4th edition of Expert Python Programming is available here.
Some jobs require a professional who uses recommended (aka best) practices. If you do not use venv for Python development, that is not going to impress your manager. If you are unsure how to use virtualenv, see this posting.
One of the following scenarios apply:
Problem scenario #1
You are trying to view namespaces on a Linux server. You run "lsns" but you get "lsns: command not found."
Problem scenario #2
You run this: sudo apt -y install util-linux
You see "util-linux is already the newest version (2.27.1-6ubuntu3.8)"
What should you do on a Debian derivative of Linux (e.g., Kali Linux, Ubuntu, Linux Mint, etc.)?
Possible Solution #1
If you are using Ubuntu Linux 16.x or lower, it may be too old to be supported. util-linux 2.28 is needed. Based on these two links (https://packages.ubuntu.com/xenial/util-linux for Ubuntu 16.x and https://packages.ubuntu.com/bionic/util-linux for Ubuntu 18.x), we think that you need a version of Ubuntu Linux higher than 16.x.
Possible Solution #2
sudo apt -y update
sudo apt -y install util-linux
If it still does not work, get the package you need from here: https://pkgs.org/download/util-linux
sudo dpkg --print-architecture
Problem scenario
You want to install MongoDB on a RHEL server. What do you do?
Solution
1. Create this file: /etc/yum.repos.d/mongodb-org-4.4.repo
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
sudo yum -y update
sudo yum -y install mongodb-org
mongod -versionIf you are using Debian or Ubuntu, see this posting.
Problem scenario
You receive a message that says "Error SSL Validation Failure" from a Chef command. What should you do?
Solution
Run this command:
knife ssl fetch https://url/of/chef/server
For more information, see this external posting (but beware of the risks of bypassing SSL).
Problem scenario
You have a Water pick for your gums and teeth (also known as a water flosser, Waterpik, or an oral irrigator). It takes time for the pressure to become optimal when you turn it on. You want the pressure to be forceful and not take time once the water basin is full and the device is on. It used to work quickly; it would start spitting out water immediately. Now there is an initial delay. What should you do now?
Possible Solution
The button the nozzle-holding device is rubber. This button when activated or pushed in temporarily stops the water from coming out can become temporarily stuck after years of use. This type of button is not what turns on the electricity to the device; however recent models have changed this and the button on the irrigating nozzle turns on the electricity to the device. The root cause of the problem this temporary-stopping button (not the on-off switch) and exists in older models (as of 2021). If you can use your water flosser and never push the temporary button in, for example by pointing the nozzle into the sink, bending over and putting your mouth over the device without turning the nozzle up, you can get the nozzle in your mouth, use it, and never get water everywhere. This rubber button can take time for the water current to clear.
For the shortest amount of time using the device, forgo the convenient temporary stop-button, use only the on-off switch when you use the water flosser. You have to point the nozzle into the sink and be careful how you adjust the angle before it is in your mouth. You mouth can catch the water and you can use the water flosser quickly and efficiently.
Another solution would be to buy a new one. (If you want to read an article about flossing, see this posting.)
Problem scenario
You want to create a Windows 2016 server in AWS. How do you do this?
Solution
1. In the AWS Console go to the EC2 Dashbaord.
2. Go to Launch Instance -> Find the AMI for Microsoft Windows Server 2016 Base and click "Select."
3. Click "Next: Configure Instance Details"
4. Click "Next: Add Storage"
5. Click "Next: Add Tags"
6. Click "Next: Configure Security Group"
7. Create or choose an existing Security Group, click "Review and Launch"
8. Click "Launch"
9. Create an existing key pair (or use an existing one if you still have the .pem file)
10. Click "Launch Instances" (even though it is only one instance)
11. Go to "Instances." Wait a minute or two.
12. Go to the "Instances" section of the AWS Console. Click the radio button for the new machine. Go to Actions -> Get Windows Password. Insert this (taken from the key pair previously created):
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
13. Click "Decrypt Password."
14. Copy down the password.
15. Open Remote Desktop Connection.
16. Type in the IP address of the machine.
17. For the username, use "administrator" with no quotes.
18. For the password, use the one obtained above in step #14.