Linux

Cronjob: Basics and reboot

One of Linux five star things is the cronjobs. They allow you to automatically run stuf (scripts, applications, etc.) at quite specific times.

The crontab is the place controlling when the stuff is run and you can list the crontab using the commaand crontab -l for the current user.

If you want to edit the crontab, just use the command crontab -e and it launches the crontab in the default editor (set EDITOR env variable to change the editor used). The format is basically like this:

Batch converting JPG and PNG to WebP

I’ve been speed optimizing some of my personal sites, and one easy update is changing the images from being JPEGs and PNG images to the smaller WebP format.

All the images I need to convert are usually in collections, where one folder at a time needs conversion and as some contain a lot of images, I needed a way to do it smartly.

This is what I came up with:

For JPEGs

find . -type f -name "*.jpg" | while read file; do cwebp -lossless "$file" -o "${file%.jpg}.webp"; done

For PNGs

find . -type f -name "*.png" | while read file; do cwebp -lossless "$file" -o "${file%.png}.webp"; done

The one-liners find all jpegs (or pngs) in the folder and converts it into a lossless webp version. It leaves the original image as a backup. For further optimizations the “cweb -lossless” could be changes to:

Automatic MacOS shutdown

From time to time my Mac is doing stuff which takes quite awhile. Converting images, converting videofiles between formats or other stuff, which may take a long time (but reasonable predictable).

In those cases I run a little command in the terminal, to automatically shut down the Mac upon completion:

sudo shutdown -h +120

This command sets a timer which shutdown the machine after two hours (the 120 parameters being after 120 minutes).

Linux - No space left on device, yet plenty of free space

My little server ran into an issue, and started reporting the error:

No space left on device

No worries, lest figure out which disk has full and clean up…

Using the df command with the -h (for human-readable output) it should be easy to find the issue:

root@server:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 483M 0 483M 0% /dev
tmpfs 100M 3.1M 97M 4% /run
/dev/vda 20G 9.3G 9.4G 50% /
tmpfs 500M 0 500M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 500M 0 500M 0% /sys/fs/cgroup
cgmfs 100K 0 100K 0% /run/cgmanager/fs
tmpfs 100M 0 100M 0% /run/user/1000

Strange. Notice who the /dev/vda is 50% fillled and all other disk devices seems to be finde too. Well after a little digging, thinking and googling, it turns out device space consists of two things - space (for data) on the device and iNodes (the stuff used to mange the space - where the data go - simplified).

Are you ready for transparency?

Running a modern IT platform is rarely an easy nor isolated task. Most platforms consist of a fairly large number of components ranging from OS level to 3. party libraries and components added in the user interfacing layers - and adding numerous integrations does make it an interesting challenge to quickly identify and correct bugs and errors.

While the system complexity does pose a challenge is surely not an impossible task, as several tools exists for most - if not all - platforms to allow instrumentation of the platform and utilize the instrumentation tools to handle the platform and identify issues quickly.