Showing a loading symbol in Bash

Rationale TL;DR

We want to be more interactive when running a long time running task in Bash

The solution

Lets use the \r escape character that resets the current line.

#!/bin/bash

frames="/ | \\ -"

while true;
do
	for frame in $frames; do
		printf "\r $frame loading..."
		sleep 0.3
	done
done

That would reset the current line. During the for loop we simply change the character from the frames array, giving the impression of activity. That is more user friendly than using a static line.

Reusing a PVC

Rationale TL;DR

Let’s suppose we have a PV and we need to attach it to a new PVC. Let’s suppose the PVC was claimed by a POD which does not exist anymore.

The solution

In this situation, the PV should be in the Released state:

pvc-ee8e4b8e-28d6-40dd-bfe8-a5affb6bc9d9   10Gi       RWO            Retain           Released   my-namespace/grafana                                     kops-ssd-1-17            352d

Of course, the Reclaim policy should be Retained otherwise there wouldn’t be the PV at all :)

We need to edit the PV and remove the claimRef field. That would make the volume Available:

pvc-ee8e4b8e-28d6-40dd-bfe8-a5affb6bc9d9   10Gi       RWO            Retain           Available           kops-ssd-1-17            352d

The next thing we need to do is create a yaml file file with the following contents (your milleage may vary, the relevant thing is to use the right PV in the claim):

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana
  namespace: my-namespace
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  volumeName: pvc-ee8e4b8e-28d6-40dd-bfe8-a5affb6bc9d9

That should create a claim and attach it to the old PV:

# kubectl get pvc
NAME      STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS    AGE
grafana   Bound    pvc-ee8e4b8e-28d6-40dd-bfe8-a5affb6bc9d9   10Gi       RWO            kops-ssd-1-17   10m

Using a better pager with MySQL

Rationale TL;DR

We’re using the CLI MySQL monitor and long lines are giving us a hard time

The solution

One solution is to use a pager like less. For example:

MariaDB [MyDatabase]> pager less -SFX

Another option I do prefer is to use pspq. Set it as your default pager with:

pager pspg -s 14 -X --force-uniborder --quit-if-one-screen

Let’s check its output:

pspq

Don’t forget to install pspq before using it. Your milleage may vary, depending on the distro…