Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[Terminal] F2 – Command-line batch renaming tool

Project: https://github.com/ayoisaiah/f2
Wiki: https://github.com/ayoisaiah/f2/wiki
Installation: https://github.com/ayoisaiah/f2/wiki/Installation

curl -LO https://github.com/ayoisaiah/f2/releases/download/v1.6.1/f2_1.6.1_linux_amd64.tar.gz
tar -xvzf f2_1.6.1_linux_amd64.tar.gz 
chmod +x f2 
sudo mv f2 /usr/local/bin 
rm f2_1.6.1_linux_amd64.tar.gz 

Renaming a file from ‘img’ to ‘Image’

# test run
f2 -f 'img' -r 'Image'
# performing the actual renaming
f2 -f 'img' -r 'Image' -x
# undo the changes
f2 -u -x

Or renaming episodes from 01_S1.MyEpisode.mp4 to S01E01.MyEpisode.mp4

f2 -f '.._S1' -r 'S01E%02d'

[ZFS] Replace failed disk on my Proxmox Host


Yesterday evening I got an email that on my Proxmox server a disk had failed. In my ZFS Raidz1 I have 4 different drives of two manufactures: 2x HGST and 2x Seagate.
In the last 7 years I also used some Western Digitals. The only faulty hard drives I had in this years were from Seagate. This was the third… So this morning I bought a new hard disk, this time a Western Digital Red, and replaced the failed disk.

SSH into my server and checked the zpool data. Because I already removed the failed disk, it’s marked as unavailable.

failed disk: wwn-0x5000c5009c14365b

Now I had to find the Id of my new disk. With fdisk -l, I found my new disk as /dev/sde, but there was no id listed.

sudo fdisk -l

To be sure I checked again with:

sudo lsblk -f

With disk by-id I now got the Id.

ls /dev/disk/by-id/ -l | grep sde

new disk: ata-WDC_WD40EFRX-68N32N0_WD-WCC7K1CSDLRT
and again the failed disk: wwn-0x5000c5009c14365b

Before replacing the disks, I did a short SMART test.

sudo smartctl -a /dev/sde
sudo smartctl -t short /dev/sde
sudo smartctl -a /dev/sde

The new disk had no errors. And because it is a new disk, I don’t had to wipe any file systems from it.

So first I took the failed disk offline. Not sure if that was necessary, because I already had removed the disk.

sudo zpool offline data 2664887927330352988

Next run the replace command.

sudo zpool replace data /dev/disk/by-id/wwn-0x5000c5009c14365b-part2
/dev/disk/by-id/ata-WDC_WD40EFRX-68N32N0_WD-WCC7K1CSDLRT

The resilver process for the 3TB disk took about 10 hours.

[Shell] Replace pattern

How to replace a specific pattern in a file or folder name. In my case I needed to correct the season on each file of a series from “S08” to “S09”:

for f in *; do mv "$f" "$(echo "$f" | sed s/S08/S09/)"; done      

If you want to replace a pattern recursive, use the command “find”:

find . -name '*' -exec bash -c 'echo mv $0 ${0/S08/S09}' {} \;    // with echo for testrun