remove/rename files with spaces in filename(s)

Let’s examine the folder structure:

Search for files with space(s) in the filename(s)

To do a search within the current folder for all files with a space in the filename do:

find . -maxdepth 1 -type f -name "* *" | while read file; do ls -la   "$file"; done |more
-rw-r--r--  1 ugu5ma  staff  8 Dec 29 14:38 ./file 2.txt
-rw-r--r--  1 ugu5ma  staff  13 Dec 29 14:38 ./file 3.txt
-rw-r--r--  1 ugu5ma  staff  6 Dec 29 14:38 ./file 1.txt

the “-maxdepth 1” parameter limits the search within the current folder.
-maxdepth 2” would search within the current and the first subfolder(s)

To do a recursive search for all files with a space in the filename do:

find . -type f -name "* *" | while read file; do ls -la   "$file"; done |more
-rw-r--r--  1 ugu5ma  staff  8 Dec 29 14:38 ./file 2.txt
-rw-r--r--  1 ugu5ma  staff  13 Dec 29 14:38 ./file 3.txt
-rw-r--r--  1 ugu5ma  staff  6 Dec 29 14:38 ./file 1.txt
-rw-r--r--  1 ugu5ma  staff  8 Dec 29 14:38 ./1/subfolder/file 2.txt
-rw-r--r--  1 ugu5ma  staff  13 Dec 29 14:38 ./1/subfolder/file 3.txt
-rw-r--r--  1 ugu5ma  staff  6 Dec 29 14:38 ./1/subfolder/file 1.txt
-rw-r--r--  1 ugu5ma  staff  8 Dec 29 14:38 ./1/file 2.txt
-rw-r--r--  1 ugu5ma  staff  13 Dec 29 14:38 ./1/file 3.txt
-rw-r--r--  1 ugu5ma  staff  6 Dec 29 14:38 ./1/file 1.txt
-rw-r--r--  1 ugu5ma  staff  8 Dec 29 14:38 ./3/file 2.txt
-rw-r--r--  1 ugu5ma  staff  13 Dec 29 14:38 ./3/file 3.txt
-rw-r--r--  1 ugu5ma  staff  6 Dec 29 14:38 ./3/file 1.txt
-rw-r--r--  1 ugu5ma  staff  8 Dec 29 14:38 ./2/file 2.txt
-rw-r--r--  1 ugu5ma  staff  13 Dec 29 14:38 ./2/file 3.txt
-rw-r--r--  1 ugu5ma  staff  6 Dec 29 14:38 ./2/file 1.txt

Rename files with space(s) in filename(s)

To replace the space with an underscore for files within the current folder execute:

find . -maxdepth 1 -type f -name "* *" | while read file; do mv "$file" ${file// /_}; done

➜  ordner ls -l
total 24
drwxr-xr-x  6 ugu5ma  staff  192 Dec 29 14:51 1
drwxr-xr-x  5 ugu5ma  staff  160 Dec 29 14:39 2
drwxr-xr-x  5 ugu5ma  staff  160 Dec 29 14:39 3
-rw-r--r--  1 ugu5ma  staff    6 Dec 29 14:38 file_1.txt
-rw-r--r--  1 ugu5ma  staff    8 Dec 29 14:38 file_2.txt
-rw-r--r--  1 ugu5ma  staff   13 Dec 29 14:38 file_3.txt

the files in the subfolders are still untouched:

ordner find . -type f -name "* *" | while read file; do ls -la   "$file"; done |more
-rw-r--r--  1 ugu5ma  staff  8 Dec 29 14:38 ./1/subfolder/file 2.txt
-rw-r--r--  1 ugu5ma  staff  13 Dec 29 14:38 ./1/subfolder/file 3.txt
-rw-r--r--  1 ugu5ma  staff  6 Dec 29 14:38 ./1/subfolder/file 1.txt
-rw-r--r--  1 ugu5ma  staff  8 Dec 29 14:38 ./1/file 2.txt
-rw-r--r--  1 ugu5ma  staff  13 Dec 29 14:38 ./1/file 3.txt
-rw-r--r--  1 ugu5ma  staff  6 Dec 29 14:38 ./1/file 1.txt
-rw-r--r--  1 ugu5ma  staff  8 Dec 29 14:38 ./3/file 2.txt
-rw-r--r--  1 ugu5ma  staff  13 Dec 29 14:38 ./3/file 3.txt
-rw-r--r--  1 ugu5ma  staff  6 Dec 29 14:38 ./3/file 1.txt
-rw-r--r--  1 ugu5ma  staff  8 Dec 29 14:38 ./2/file 2.txt
-rw-r--r--  1 ugu5ma  staff  13 Dec 29 14:38 ./2/file 3.txt
-rw-r--r--  1 ugu5ma  staff  6 Dec 29 14:38 ./2/file 1.txt

To replace the space with an underscore for files within the current folder and subfolders execute:

find . -type f -name "* *" | while read file; do mv "$file" ${file// /_}; done

Danger zone: delete files in current and subfolder with space(s) in filename(s)

find . -type f -name "* *" | while read file; do rm "$file"; done

Pi-hole: send pihole.log and pihole-FTL.log to external Syslog-server

The option to send Pihole-logs to a remote syslogserver is not implemented.
Good thing is that Pi-hole creates log-files.
How about adding these logfiles to the local (R-)Syslog-daemon and send it over to the external Syslog-Server via port 514 TCP/UDP ?

I use Dietpi as the OS on my Raspi3+ and added Pi-hole as one of the supported apps .

Dietpi has per default noSyslog-daemon activated.
The first step is to install a Syslog-daemon, in my case Rsyslog.
Install with root-privileges (sudo su):

apt install rsyslog

cd to /etc/rsyslog.d and create two files:

nano pihole.conf

$InputFileName /var/log/pihole.log
$InputFileTag pihole
$InputRunFileMonitor
$InputFilePersistStateInterval 1000
nano piholeftl.conf

$InputFileName /var/log/pihole-FTL.log
$InputFileTag pihole-ftl
$InputRunFileMonitor
$InputFilePersistStateInterval 1000

as next alter rsyslog.conf and add the following lines

nano /etc/rsyslog.conf

$ModLoad imfile
$InputFileName /var/log/pihole.log
$InputFileName /var/log/pihole-FTL.log
*.* @10.50.100.5:514

10.50.100.5 is the external Syslog-Server. Dietpi sends now the syslog-information to the Syslog-Server 10.50.100.5 via TCP port 514.
Change the IP 10.50.100.5 to the Syslog-Server IP you want to use.

restart Rsyslog-daemon:

systemctl restart rsyslog

The Syslog-daemon receives now the Pi-hole logs:

Addition: If you want to see also the DNS-queries go to Settings and Enable query logging:

This brings also the DNS content to the external Syslog-Server:

May 14 09:58:27 DietPi local0 pihole May 14 09:58:26 dnsmasq[15529]: query[A] bier.de from 10.50.100.13
May 14 09:58:27 DietPi local0 pihole May 14 09:58:26 dnsmasq[15529]: forwarded bier.de to 1.0.0.1
May 14 09:58:27 DietPi local0 pihole May 14 09:58:26 dnsmasq[15529]: dnssec-query[DS] bier.de to 1.0.0.1
May 14 09:58:27 DietPi local0 pihole May 14 09:58:26 dnsmasq[15529]: reply bier.de is no DS
May 14 09:58:27 DietPi local0 pihole May 14 09:58:26 dnsmasq[15529]: reply bier.de is 212.53.128.75
May 14 09:58:27 DietPi local0 pihole May 14 09:58:26 dnsmasq[15529]: query[AAAA] bier.de from 10.50.100.13
May 14 09:58:27 DietPi local0 pihole May 14 09:58:26 dnsmasq[15529]: forwarded bier.de to 1.0.0.1
May 14 09:58:27 DietPi local0 pihole May 14 09:58:26 dnsmasq[15529]: reply bier.de is NODATA-IPv6

Done!

fix openhab error: Rule ‘[rulename]’: An error occurred during the script execution: index=0, size=0

My goal is to execute an python-script when the Battery-charge has reached 70%

My rule was not executed, the error as shown above is seen in the log.
My faulty script:

rule "BYD 70"

when
     Item KOSTALPLENTICOREPlus70WithBattery_BatteryCharge received update



then
	var BYDBat = (KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state as Number).floatValue

	if ((KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state as Number).floatValue = 70.0) {


	sendTelegram("bot1",
            "BYD hat > 70  % Ladung " + BYDBat)
	executeCommandLine("python3 /etc/openhab2/scripts/BYDI.py")
	logDebug("logtest", "BYDBat = " + BYDBat)
        logDebug("logtest", "state = " + KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state)
}

end

Reason of the error: the if-statement is misleading, to check if the value is equal it needs two “==”:


	if ((KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state as Number).floatValue == 70.0) {

working-code:

rule "BYD 70"

when
     Item KOSTALPLENTICOREPlus70WithBattery_BatteryCharge received update



then
	var BYDBat = (KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state as Number).floatValue

	if ((KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state as Number).floatValue == 70.0) {


	sendTelegram("bot1",
            "BYD hat > 70  % Ladung " + BYDBat)
	executeCommandLine("python3 /etc/openhab2/scripts/BYDI.py")
	logDebug("logtest", "BYDBat = " + BYDBat)
        logDebug("logtest", "state = " + KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state)
}

end

to debug BYDBat/KOSTALPLENTICOREPlus70WithBattery_BatteryCharge.state debugging needs to be enabled like shown at: https://www.cipv6.de/worp/index.php/2019/10/23/how-do-i-debug-tradfri-on-openhab/

openhab> log:get org.eclipse.smarthome.model.script
DEBUG
openhab> log:set Info org.eclipse.smarthome.model.script
openhab> log:get org.eclipse.smarthome.model.script
INFO

Send Geo-location from Browser

Create a button and log the current LAT/LON when the button is pressed:

<button id="send-location"> Send location</button>
document.querySelector('#send-location').addEventListener('click', () => {

    if (!navigator.geolocation) {

        return alert ('Geolocation not supported by Browser !')

    }
    
    navigator.geolocation.getCurrentPosition((position) => {

        console.log(position)

    })

console.log output