Category: Software Howtos

Check if a file is a valid JSON in a BASH script

So, you have downloaded a file that is supposed to be a JSON. Before processing the file, it might be wise to check if that file is actually a valid JSON file.

Here is how to check if a file is indeed a valid JSON file:

if jq empty $File 2>/dev/null; then
  ThisFileIsAValidJSONFile="true"
else
  ThisFileIsAValidJSONFile="false"
fi 

Activate maintenance mode for nextcloud from BASH command line

Sometimes, one wants to put a nextcloud installation into “Maintenance mode” from the command line. Assuming your nextcloud is installed in /var/www/nextcloud/, the following command will put it in maintenance mode:

sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on

The following command will deactivate maintenance mode:

sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off

If you want to check the state of maintenance mode:

if [ "$(sudo -u www-data php /var/www/nextcloud/occ status | grep -c "maintenance: true")" != "0" ]; then
  echo "Nextcloud is in maintenance mode"
else
  echo "Nextcloud is not in maintenance mode"
fi

Activate maintenance mode for wordpress from BASH command line

Sometimes, one wants to put a wordpress installation into “Maintenance mode” from the command line. Assuming your wordpress blog is installed in /var/www/myblog.example.com/, the following command will put it in maintenance mode:

echo '<?php $upgrading = '"$(date +%s)"'; ?>' > /var/www/myblog.example.com/.maintenance

The following command will deactivate maintenance mode:

rm -f /var/www/myblog.example.com/.maintenance

How to query the name and directory of a Bash script

Once in a while, a Bash script needs to query its own name and directory. Here is an example on how to do that:

#!/usr/bin/bash

ThisScriptsName="$(basename -- "${BASH_SOURCE[0]}")"
ThisScriptsDirectoryAndName="$(readlink -f -- "${BASH_SOURCE[0]}")"
ThisScriptsDirectory="$(dirname -- "$ThisScriptsDirectoryAndName")"
TheCurrentDirectory="$(pwd)"

printf 'ThisScriptsName: %s\n' "$ThisScriptsName"
printf 'ThisScriptsDirectoryAndName: %s\n' "$ThisScriptsDirectoryAndName"
printf 'ThisScriptsDirectory: %s\n' "$ThisScriptsDirectory"
printf 'TheCurrentDirectory: %s\n' "$TheCurrentDirectory"

#EOF

Let’s assume the name of the file is WhatsMyNameAndLocation, and it is located in /usr/scripts and executed from / with /usr/WhatsMyNameAndLocation:

ThisScriptsName: WhatsMyNameAndLocation
ThisScriptsDirectoryAndName: /usr/scripts/WhatsMyNameAndLocation
ThisScriptsDirectory: /usr/scripts
TheCurrentDirectory: /

Activate IP forwarding on Debian 13

If you want to set up some kind of routing (of IP packets) on Debian 13, you first have to ensure that “Forwarding” is activated. By default it isn’t. Activation of Forwarding means that packets coming in at one interface might be transferred to another interface.

The following two commands will show you if forwarding is activated (“1”) or not (“0”):

sysctl net.ipv4.ip_forward
sysctl net.ipv6.conf.all.forwarding

if forwarding is not activated, the following two lines will activate it temporarily (until reboot of the system):

sysctl -w net.ipv4.ip_forward=1
sysctl -w net.ipv6.conf.all.forwarding=1

To make this persistent (“Survive a boot”), create a file /etc/sysctl.d/99-ip-forward.conf with the following two lines as content:

net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1

Finally activate this file with

sysctl -p /etc/sysctl.d/99-ip-forward.conf

To verify that it is working check it (after a reboot) with the following two commands:

sysctl net.ipv4.ip_forward
sysctl net.ipv6.conf.all.forwarding

Both commands should deliver “1”.

Rustdesk

What is Rustdesk?

RustDesk is an open-source remote desktop software that allows you to access another PC’s desktop, for example to help friends and family when they have problems, or let them help you.

It is a free alternative to TeamViewer, AnyDesk, and similar programs.

A client application is needed on both PCs. A remote desktop access is only possible when the client is started, access is impossible without the Client being started, so the user is always in control.

How to install:

Download the latest Rustdesk client from here: https://rustdesk.com
Once downloaded, start the file:

In the lower left corner, click on “Install”.

Adapt to your needs and click on “Accept and install”.

Afterwards, you should have an Icon for Rustdesk on your desktop, and Rustdesk should be running:

Click on the “three dots” (as marked in the picture), select “Network” and click on “Unlock network settings”, the select “ID/Relay server”:

Fill the fields with the following data:

rustdesk.landrocks.world
rustdesk.landrocks.world
https://rustdesk.landrocks.world
C4LDY6WziONSwEzlIiBz1x3ZFn3iR8L4kjd6ZFJZPTE=

It should look like this:

Press OK, and click on “Home” in the upper left corner.

Congratulations, you have successfully installed a Rustdesk client on your system.

How to use Rustdesk:

On the left side you see your ID and your password. If you give this to somebody else, he or she can access your desktop.

If somebody else gives you his/her ID from their left side of the window, you can access his/her desktop by entering that ID in the “Control Remote Desktop” field and clicking “connect”.

Right-click Context menu in Windows 11

The behaviour of the Context menu on Windows 11 has changed compared to Windows 10.

This is how it used to be on Windows 10 (in this example, after a Right click on the recycle bin):

And this is how it looks now:

Especially the Show more options in the last line is annoying.

Thankfully one can revert to the old behaviour of Windows 10. All you have to do is to add a key to the registry.

To do so, Right click on the four blue tiles and select Terminal (Admin):

Then, run the command

reg.exe add "HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32" /f /ve

After rebooting the Computer or restarting Explorer via Task Manager, you will have the “old” behaviour back.

That’s lovely. However, you sometimes have junk in the right-click context menu that is unwanted.

For example, I use the Image Viewer “IrfanView” but I do not like the fact that it added an entry to the context menu:

Here is how to edit/remove unwanted items from the context menu:

Right click on the four blue tiles and select Terminal (Admin), then type regedit and press <Enter>:

Select “Edit/Find” and look for “IrfanView”:

Now keep pressing <F3> until this…

and this…

… showed up. I deleted them both and the annoying entries were gone (after a Restart of Explorer).