Journal of my recent activities

Auto re-mount USB drive on linux server

This script is especially useful after a server reboot, when the USB drive sometimes fails to mount automatically.

sudo apt-get install udisks2
blkid /dev/sdb1
#!/bin/bash
MOUNT_POINT="/mnt/usb/adata-backup"
DEVICE_UUID="XXXXXXXXXXXXXXXXXXXXXX"

if ! mountpoint -q "$MOUNT_POINT"; then
    echo "Mounting drive"
     mount /dev/sdb1 /mnt/usb/adata-backup
fi

And add it to the cron tab to be run every hour.

#soft #linux #proxmox

💻 Mac user frustrated with Home/End keys?

Here is the gist that remaps Home and End to work like on Windows/Linux-jumping to the beginning/end of the line, not the whole document!

#macos #soft

By default, the microphone key on some Keychron models doesn’t trigger macOS dictation. With Karabiner-Elements, you can remap that key to launch dictation or any other system function.

This setup allows you to start voice dictation with a single key press, improving workflow efficiency.

To make the microphone key on a Keychron keyboard activate dictation in macOS, follow these steps:

  1. Open Karabiner-Elements
  2. Go to Complex Modifications → Add your own rule
  3. Paste this script.

#macos

This script is useful if you want to see two full weeks at once in the macOS Calendar app, instead of just the standard 7-day week view. I use it every Monday morning to review what I didn’t finish last week and to plan my tasks for the upcoming days.

Command:

defaults write com.apple.iCal n\ days\ of\ week $dni

Script

#soft #macos

Wyświetlania paska postępu operacji

pv jest to narzędzie do monitorowania przepływu danych przez potoki w systemie Unix/Linux. Wyświetla pasek postępu, prędkość transferu danych, czas, jaki upłynął, i szacowany czas pozostały do zakończenia operacji.

-p: Wyświetla pasek postępu.
-t: Pokazuje upływający czas.
-r: Pokazuje prędkość transferu danych.
-e: Pokazuje szacowany czas zakończenia operacji.

Na przykład jeśli chcemy śledzić postęp rozpakowywania pliku:

pv -ptre /home/backup/backup.dump.gz | gunzip > /tmp/backup_dump

Co robi ta komenda?

Ta komenda wykonuje następujące kroki:

  1. Odczyt pliku skompresowanego: pv odczytuje plik /home/backup/backup.dump.gz.
  2. Monitorowanie przepływu danych: pv wyświetla pasek postępu, prędkość transferu, czas, który upłynął, oraz szacowany czas zakończenia operacji.
  3. Dekompresja pliku: Dane są przekazywane przez pipe (|) do gunzip, który dekompresuje zawartość.
  4. Zapis zdekompresowanego pliku: Zdekompresowane dane są przekierowywane do pliku /tmp/backup_dump.

#linux #soft

If external servers are blocking access from our IP (blacklist), one solution is to swap the gateway in the private network, through which machines access the Internet.

  1. Network > Gateway
  2. Remove the existing Gateway and create a new one

Private network addresses of your machines, obtained by DHCP should not be changed.

As a result of this operation, there may be situations where Floating IPs pointing to instances in the network stop working, even though everything looks OK in the OVH panel. Then, you need to enter through the Horizon panel and there perform the detachment and reassignment of the floating IP to the instance anew.

#ovh #network #gateway

Sending email from cron

Use the MAILTO environment variable to send any output generated by your script to your email address.

MAILTO=email@example.com
0 */2 * * * /bin/backup.sh

If your script normally produces output but you don't care about it in cron, just sent it to /dev/null and it'll email you only when something is written to stderr.

MAILTO=email@example.com
0 */2 * * * /bin/backup.sh > /dev/null

serverfault.com

#linux #cron

Readwise - a game-changer in reviewing valuable book highlights. Now I receive them in my email daily like clockwork. 📚💼

#productivity

Run wireguard client on linux

cp wg0.conf /etc/wireguard
wg-quick wg0

#linux #wireguard