Archive for category linux

Bash: The let Keyword

📅 March 18, 2024
JavaScript has the let keyword that creates a variable with scope.

Bash has the let keyword too, but it serves a different purpose.

Read the rest of this entry »

,

Leave a comment

What is nohup?

📅 March 17, 2024
“Help! I need to keep a program running after closing the terminal.”

There can be times when we connect to a remote system via SSH, for example, and we need to run a lengthy process on the remote system. However, we also might need to log out or close the connection, but we want the process to continue running.

Normally, the process terminates when the terminal is closed.

nohup is a way to keep a remote process running even after the terminal is closed.

Read the rest of this entry »

,

Leave a comment

Redundant Synchronized Pi-Hole with keepalived and gravity-sync

📅 March 4, 2024
“Help! When Pi-Hole goes down, nobody can access the Internet!”

Pi-Hole is a superb network-wide ad blocker because it blocks connections to forbidden domain names listed in its blocklists when resolving DNS requests, but if Pi-Hole hangs up or is inadvertently turned off for whatever reason, then domain names cannot be resolved and it seems like the Internet is down.

To help protect against this and provide some form of resiliency, we can mirror two Pi-Hole instances so if one goes down, the backup will take over, and users can still access the Internet.

This is simpler than it sounds thanks to a service called keepalived. Let’s see how to set up two Pi-Hole instances using a virtual IP address (VIP) to provide high availability (HA).

Read the rest of this entry »

, ,

Leave a comment

Bash: Read JSON File to Add Many Users

📅 February 22, 2024
“Can Bash parse a JSON file?”

Yes, but not natively like Python can using the json module.

Parsing a JSON file from a Bash script usually involves writing custom code that parses strings and such, but there is a handy program call jq that handles the details of JSON parsing for use.

Suppose we want to add a batch of user accounts, each user with a unique password and assignment to a Linux specific group. This involves more user information that a simple username with a temporary common password. We can store this user information in a JSON file, and then let a Bash script process the user data from the file to create the users.

Here is one way to achieve this.

Read the rest of this entry »

, , ,

Leave a comment

Add New Users from a Text File

📅 February 21, 2024
“I have a LOT of users to add, but I do not want to add them one by one. Can I use a script?”

Yes! This is what Linux specializes in. We can write a script that reads a list of usernames from a text file to create these users on a given system and assign them all a default password.

Here is one way to achieve this magic.

Read the rest of this entry »

, ,

Leave a comment

How to Change Your Linux Hostname

📅 February 18, 2024
“How do I change the name of my computer without reinstalling it?”

The name of your Linux computer is called a hostname, and it can be changed anytime by the administrator.

Most of the time, the name you assign to your Linux installation need never be changed, but there are situations where this is necessary. For example, duplicating VMs or accidental duplicate naming by two different people. If you use LibreNMS, then you cannot add devices with duplicate hostnames. Therefore, a hostname might need to be changed.

No, you do not need to reinstall your entire OS. In fact, it is easy with a few commands and a reboot. Here are two ways to rename the hostname.

Read the rest of this entry »

, ,

Leave a comment

Bash2048 – A 2048 Game in the Terminal

📅 February 12, 2024
Remember the game 2048? Let’s play it in a terminal!

Here is a fun variation on the addictive “How far can you go?” number combining puzzle game — but from a bash script.

Read the rest of this entry »

, , ,

Leave a comment

cmatrix – Falling ASCII Characters

📅 February 9, 2024
“I want to impress others who look over my shoulder.”

In a world of point, click, and swipe, nothing scares people like the command line.

Well, let’s put some real fear into them with cmatrix!

Just let this run in its own terminal adjacent to BpyTOP or bmon to geek out your desktop.

Read the rest of this entry »

,

Leave a comment

asciiquarium – The Cutest Lil’ Aquarium for your Terminal

📅 February 5, 2024
“What? An animated ASCII art aquarium that runs in a terminal? Yes!”

ASCII art is fun, but animated ASCII art is even more impressive. Why not brighten your day with a secondary terminal filled with marine life as you use Linux?

ASCIIQuarium is one of those rare gems that few seem to know about but always provides hours of entertainment in the background once discovered. It is as essential as sl, cowsay, and fortune, so why not?

Let’s have fun!

Read the rest of this entry »

, ,

Leave a comment

Monitor Network Connections with nmcli

📅 February 4, 2024
If you use a Linux distribution, such as Ubuntu or Linux Mint, then you probably have NetworkManager installed. NetworkManager handles network connectivity, and you have probably already interacted with it via a GUI interface when setting up a network connection from the panel.

But did you know that NetworkManager can also be controlled from the command line?

nmcli is the command-line tool that allows us to perform NetworkManager functions straight from the terminal. This is good news because it means we can script NetworkManager’s behavior as boot up tasks or cron jobs. In fact, we can use nmcli to show all current network connections in a custom gnome-terminal.

Here are a few examples for nmcli.

Read the rest of this entry »

, , ,

Leave a comment