How to handle ACPI events on Linux

ACPI is the acronym for Advanced Configuration and Power Interface; as a standard, it was first implemented in the year 1996, as a successor to APM (Advanced Power Management). As a main feature, it brought the ability to handle power management at the operating system level, whereas before it was handled in BIOS. Some ACPI events on Linux are, by default, handled via systemd-logind, but more complex configurations can be achieved by installing and running the acpid service.

Read more

How to use graphical widgets in bash scripts with zenity

Zenity is a very useful utility which let us create graphical user interfaces for our shell scripts. Several widgets exists, and can be used by invoking the program with the respective options. The widgets are based on the GTK toolkit, and return the result of the user interaction either on the standard output or as a return code.

In this tutorial you will learn:

  • What are the general zenity options
  • What are the some of the most useful available widgets and how to use them

Read more

Customizing vim for development

Introduction

Of course, we wouldn’t have had it any other way: we wanted to be fair, as pledged, so here is the vim article, which is a counterpart of our last one on how to make your editor the perfect programming environment. So you must have the following profile for this article to be really useful to you: you know your way around programming, so you subsequently know what you would like in an editor, and you also know your way around vim, preferably more than what we talked about in the article dedicated to it. If you read the customizing emacs article, you already have a good idea on how this article is going to be structured. If you were directed here from somewhere else, here’s what we’re gonna do: we’ll take some popular programming language (space permitting) and show you how to tweak vim so it will became more fit for coding in that language.

The languages

Although vim is written entirely in C, there is something named vimscript that makes creating/editing settings, sort of like Elisp in emacs, although this is a loose comparison. Please remember that whatever will be talked about here is only about vim. Not BSD vi, not some vi extension for another editor, just vim. That is because although you can learn the basics on, say, nvi, the things that interest us (since you already know the basics) will only work on vim. Of course, some recent version, not older than 7.3.x. Many things will probably work on 7.x or maybe even 6.x, but there’s no guarantee.

Just as before, a little advice: although this is influenced by personal preference, experience says it works; namely, install scripts/addons/color schemes directly from the source, regardless if your distro offers it as well. That’s because many maintainers tend to package stuff with respect to their personal preference, which might or might not be in concordance with yours. Installing such addons is as simple as copying a file to a location, nothing more. And, for your convenience, we’ll tell you how to install via your package manager anyway.

The distributions I have available to me at this point are Debian, Fedora, Gentoo and Arch. I will do a search for the ‘vim’ keyword on each of them and give you some tips and pointers on what you can install, then we’ll go language-specific.

Read more

Python OS Module

Introduction

Python is a powerful scripting language. So, why not use it to script Linux? The os module is Python’s answer to handling many Linux file operations.

The os module allows Python to perform many of the file and folder operations that you’d typically carry out in the Linux command line. It enable you to begin swapping out Bash for Python, which makes for a much cleaner and friendlier scripting experience.

Loading OS

The os module is a Python module like any other. In any script where you want to use it, you can use an import statement to pull it in.

import os

getcwd()

The getcwd() method returns the current working directory in the form of a string. You don’t need to pass it anything. It’s roughly the equivalent of pwd.

print(os.getcwd())

Read more

Automate Dynamic IP Updates for Your Domain with Cloudflare and Bash Script

Automate Dynamic IP Updates for Your Domain with Cloudflare and Bash Script

In a world where static IP addresses are often an added expense, dynamic IP addresses can make managing domains a challenge. If your ISP assigns you a dynamic IP address, keeping your domain updated can be a hassle. This tutorial will walk you through creating a simple yet effective Bash script that uses Cloudflare’s API to update your domain’s DNS record whenever your IP changes. With this script, you can ensure that your domain always points to your current dynamic IP address, even without a static IP.

Read more

Useful Bash command line tips and tricks examples – Part 2

In this series we are exploring various tips, tricks and Bash command line examples which will help you become a more advanced Bash user and coder. Bash provides a rich scripting and coding language which puts the power back in the hands of the user and developer. Bash also allows you to learn as you go along, thereby making it a more enjoyable experience. For the first article in our series, please see our article Useful Bash command line tips and tricks examples part 1.

In this tutorial series you will learn:

  • Useful Bash command line tips, tricks and methods
  • How to interact with the Bash command line in an advanced manner
  • How to sharpen your Bash skills overall and become a more proficient Bash user

Read more

How to create a hot standby with PostgreSQL

How to create a hot standby with PostgreSQL

With databases such as PostgreSQL, the need may arise to scale and provide high availability. If the database does not have a backup which can take its place in case of failure, then all of your operations that depend on the database can be affected from just a single point of failure. Even with virtual systems, there may be a time when you can’t add more resources to a single machine to cope with the ever-increasing load.

Read more

Linux Subshells for Beginners With Examples

Making use of bash subshell in Bash provides you with an ability to generate context sensitive information from right within your Bash command. For example, if you want to modify a text string right inside an echo statement, then this can be done easily with subshells.

In this tutorial you will learn:

  • How to use employ the use of subshells in Bash
  • How to use subshells to obtain context sensitive information
  • Basic Bash subshell usage examples

Read more