pponce/homebridge-script2

Call Synology Docker and .sh Script

Closed this issue · 3 comments

First of all thank you for the great plugin.

Unfortunately, it does not work as I would like. Plugin starts and the switch is also visible in ios. If I activate the switch but the script is not executed. My machine is a Synology and the homebridge runs in a dock container. The rights of the files I have checked with WinSCP, all rights are granted. The paths of the respective scripts also fit. When I run the scripts through the Task Scheduler, the scripts also run, but unfortunately not via the switch in ios. Do you have an idea and maybe you can help me?

"/volume1/DiskStation/Programme/USB-Festplatten/Krabbi/USB_KRABBI_21.sh":

#!/bin/bash
touch "/volume1/DiskStation/Programme/USB-Festplatten/Krabbi/USB_KRABBI_21.flag"

echo '3-2' | tee /sys/bus/usb/drivers/usb/bind
sleep 30

AUSWAHLDATUM="2018-11-17"

QUELLE1="/volume1/DiskStation/- Konzerte"
QUELLE2="/volume1/DiskStation/- Filme"
QUELLE3="/volume1/DiskStation/- Kinderfilme"
QUELLE4="/volume1/DiskStation/- Serien"

ZIEL1="/volumeUSB21/usbshare/- Konzerte"
ZIEL2="/volumeUSB21/usbshare/- Filme"
ZIEL3="/volumeUSB21/usbshare/- Kinderfilme"
ZIEL4="/volumeUSB21/usbshare/- Serien"

LOGPFADFINAL="/volume1/DiskStation/Programme/USB-Festplatten/Krabbi/Log Final.txt"
LOGPFADTEMP="/volume1/DiskStation/Programme/USB-Festplatten/Krabbi/Temp.txt"
LOGFEHLERPFAD="/volume1/DiskStation/Programme/USB-Festplatten/Krabbi/Fehler.txt"

timestamp() {
  date +"%d.%m.%Y - %T"
}

before=$(date)

cd "$QUELLE1" && find -not \( -path "*@eaDir*" -prune \) -type f \( -name "*.mkv" -or -name "*.avi" -or -name "*.mp4" \) -newermt "$AUSWAHLDATUM" -exec cp -uv --parents "{}" "$ZIEL1" 2>> "$LOGFEHLERPFAD" 1>> "$LOGPFADTEMP" \; | awk 'BEGIN{c=0; do{printf "#"; c++}while(c<120); printf "\n \n"}' >> $LOGPFADTEMP

cd "$QUELLE2" && find -not \( -path "*@eaDir*" -prune \) -type f \( -name "*.mkv" -or -name "*.avi" -or -name "*.mp4" \) -newermt "$AUSWAHLDATUM" -exec cp -uv --parents "{}" "$ZIEL2" 2>> "$LOGFEHLERPFAD" 1>> "$LOGPFADTEMP" \; | awk 'BEGIN{c=0; do{printf "#"; c++}while(c<120); printf "\n \n"}' >> $LOGPFADTEMP

cd "$QUELLE3" && find -not \( -path "*@eaDir*" -prune \) -type f \( -name "*.mkv" -or -name "*.avi" -or -name "*.mp4" \) -newermt "$AUSWAHLDATUM" -exec cp -uv --parents "{}" "$ZIEL3" 2>> "$LOGFEHLERPFAD" 1>> "$LOGPFADTEMP" \; | awk 'BEGIN{c=0; do{printf "#"; c++}while(c<120); printf "\n \n"}' >> $LOGPFADTEMP

cd "$QUELLE4" && find -not \( -path "*@eaDir*" -prune \) -type f \( -name "*.mkv" -or -name "*.avi" -or -name "*.mp4" \) -newermt "$AUSWAHLDATUM" -exec cp -uv --parents "{}" "$ZIEL4" 2>> "$LOGFEHLERPFAD" 1>> "$LOGPFADTEMP" \; | awk 'BEGIN{c=0; do{printf "#"; c++}while(c<120); printf "\n \n"}' >> $LOGPFADTEMP

awk 'BEGIN{c=0; do{printf "-"; c++}while(c<27); printf "\n"}' >> $LOGPFADTEMP
echo -e "Diese Daten wurden kopiert:" >> $LOGPFADTEMP

gesamtspeicherplatzderfestplatte() {
  df -h /volumeUSB21/usbshare | awk '/^\/volumeUSB21/usbshare { print $2 }' | tail --lines +2 | sed 's/G.*/ Gigabyte/g; s/T.*/ Terabyte/g; s/M.*/Megabyte/g'

}

belegterspeicherplatz() {
  df -h /volumeUSB21/usbshare | awk '/^\/volumeUSB21/usbshare { print $3 }' | tail --lines +2 | sed 's/G.*/ Gigabyte/g; s/T.*/ Terabyte/g; s/M.*/Megabyte/g'

}

freierspeicherplatz() {
  df -h /volumeUSB21/usbshare | awk '/^\/volumeUSB21/usbshare { print $4 }' | tail --lines +2 | sed 's/G.*/ Gigabyte/g; s/T.*/ Terabyte/g; s/M.*/Megabyte/g'
}

belegterspeicherplatzinprozent() {
  df -h /volumeUSB21/usbshare | awk '/^\/volumeUSB21/usbshare { print $5 }' | tail --lines +2
}

after=$(date)
timeDiff=$(date -u -d @$(($(date -d "$after" '+%s') - $(date -d "$before" '+%s'))) '+%M:%S')

echo -e """\n""Freier Speicherplatz:"" $(freierspeicherplatz) \t\t "Festplatten-Größe:" $(gesamtspeicherplatzderfestplatte)" >> $LOGPFADTEMP
echo -e "\nBelegter-Speicherplatz:" $(belegterspeicherplatz)" \t "Belegter-Speicherplatz:" $(belegterspeicherplatzinprozent)" >> $LOGPFADTEMP
echo -e "\nScript-Laufzeit:" $timeDiff "Minuten/Sekunden" >> $LOGPFADTEMP

echo -e "\nStartzeitpunkt: $(timestamp)\n" >> $LOGPFADTEMP

tac "$LOGPFADTEMP" | sed 's/^.*-> /-> /' > "$LOGPFADFINAL"

sleep 30
echo '3-2' | tee /sys/bus/usb/drivers/usb/unbind

exit 0

"/volume1/DiskStation/Programme/USB-Festplatten/Krabbi/USB_KRABBI_21_OFF.sh":

#!/bin/bash rm "/volume1/DiskStation/Programme/USB-Festplatten/Krabbi/USB_KRABBI_21.flag" exit 0

Thanks and best regards
Seger

When you say all rights are granted. Can you confirm that the same “user” that runs homebridge also has access to execute the script?
In my case the user is a user named “homebridge” that needs script execution rights.

So in my system it is the user "Seger" who is also Admin and also runs Docker. At least that's how it should be. "Seger" is also Admin and has the rights 777 granted via WinSCP. Would not know where the error lies, what can it have to do with root and synology? Would be totally grateful if we get along together. Thanks and best regards Seger

I’m not familiar with docker and how homebridge runs with docker.
Can you try executing your script as a different user? See if it works as a different user?