Jump to content


Photo

script in background with hotkey and name !dvdbackup_to_dvd_complete.sh


  • Please log in to reply
2 replies to this topic

#1 Pike_Bishop

  • Senior Member
  • 1,130 posts

+72
Good

Posted 20 October 2019 - 18:49

Hi,

 

first, what is the difference if i name a script dvdbackup_to_dvd_complete.sh or !dvdbackup_to_dvd_complete.sh ?

i ask this because i can't see a difference at the execution in the openpli-7.2rc on the vu ultimo 4k

 

as example i have here since years a script which can copy a dvd from a usb dvd-drive to the hdd as dvd structure (VIDEO_TS,AUDIO_TS)

it is named dvdbackup_to_dvd_complete.sh and i start it with a hotkey, it looks as following;

#!/bin/bash

## Variablen ##
BOXIP=http://localhost

DVDBACKUP_PACKAGE=dvdbackup
DVDBACKUP=/usr/bin/dvdbackup
NICE=/bin/nice
NICE_ARGS="-n 19"
WGET=/usr/bin/wget

DVD_ROM=/dev/sr0

HDD=/media/hdd
TARGETDIR=$HDD/movie/_Converted/video/dvdbackup
WORKDIR=$HDD/movie/_Converted/_temp
DVD_INFO=$WORKDIR/dvd_info.txt
TMP=/tmp
LOGFILE=$TMP/dvdbackup.log


# Konsole (Fenster im OSD am TV) schliessen damit man das bei Ausfuehrung
# direkt an der Box mit z.b: Hotkey nicht selbst zu tun braucht.
sleep 3
$WGET -q -O - $BOXIP/web/remotecontrol?command=352


# Generelles Logging.
##exec >$LOGFILE; exec 2>&1 (funktioniert nicht in der bash (OpenATV ab Version 4.2 hat bash an Board))
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>$LOGFILE 2>&1


# Falls das Script erneut gestartet wird da es zuvor aus welchem Grund auch
# immer abgebrochen ist, die eventuell verbliebenen Altlasten loeschen.
if [ -d $WORKDIR/*/ ] ; then
	$NICE $NICE_ARGS rm -rf $WORKDIR/*/
fi


# Job Start/Startzeit
STARTDATE="$(date +%a.%d.%b.%Y-%H:%M)" && echo -e "\n\nJOB START -> $STARTDATE\n\n" && sleep 7
$WGET -O - -q "$BOXIP/web/message?text=Starte%20DVD%20kopieren%20...%20->%20$STARTDATE&type=1&timeout=10" > /dev/null && sleep 5


# OSD Fehler Ausgabe.
osd_error_message() {
	sleep 11
	$WGET -O - -q "$BOXIP/web/message?text=ABBRUCH%20---%20(%20Details%20dazu%20in%20$LOGFILE%20)&type=3" > /dev/null
	echo ""
}


# Benoetigtes Paket (dvdbackup) nachinstallieren falls nicht vorhanden.
if [ ! -f $DVDBACKUP ] ; then
opkg update

		if [ "$?" = "0" ] ; then
			echo -e "\nPaketmanagement Aktualisierung erfolgreich.\n"
			opkg install $DVDBACKUP_PACKAGE

				if [ "$?" = "0" ] ; then
					echo -e "Installation Programm $DVDBACKUP_PACKAGE erfolgreich.\n"
				else
					osd_error_message
					echo "ABBRUCH !\nInstallation Programm $DVDBACKUP_PACKAGE fehlgeschlagen."
					echo -e "Bitte Programm $DVDBACKUP_PACKAGE manuell installieren,\nund das Script erneut starten.\n" && exit 1
				fi

		else
			osd_error_message
			echo -e "\nABBRUCH !\nPaketmanagement Aktualisierung fehlgeschlagen -> Netzwerkverbindung pruefen."
			echo "Oder das Programm $DVDBACKUP_PACKAGE manuell installieren,"
			echo -e "da dieses fehlt aber unbedingt erforderlich ist, damit das Script laeuft.\n" && exit 1
		fi

else
	echo -e "\nProgramm $DVDBACKUP_PACKAGE ist vorhanden.\n"
fi


# Benoetigte Verzeichnisse erstellen falls nicht vorhanden.
if [ ! -d $TARGETDIR -o ! -d $WORKDIR ] ; then
	echo ""
	for verz in $TARGETDIR $WORKDIR
	do
		mkdir -p $verz

		if [ "$?" = "0" ] ; then
			echo -e "\nVerzeichnis;\n$verz\nerfolgreich angelegt.\n"
		else
			osd_error_message
			echo -e "\nABBRUCH !\nVerzeichnis;\n$verz\nanlegen fehlgeschlagen."
			echo -e "Bitte manuell erstellen,\nund das Script erneut starten.\n" && exit 1
		fi
	done
fi


# Berechnung ob genuegend Speicherplatz auf der HDD vorhanden ist um die DVD zu kopieren.
# Benoetigt wird hier in etwa die DVD-Groesse + zur Sicherheit noch ca. 200 Mb mehr.
DVDSIZE="$(df -m $DVD_ROM | grep '/' | awk {'print $3'})"
DVDSIZE=`expr $DVDSIZE + 200`

HDDFREE="$(df -m $HDD |grep $HDD |awk '{print $4}')"

if [ "$DVDSIZE" -ge "$HDDFREE" ] ; then
	DIFFERENCE=`expr $DVDSIZE - $HDDFREE + 200`
	osd_error_message
	echo "ABBRUCH !\nZu wenig freier Plattenplatz."
	echo "Bitte zusaetzlich ungefaehr $DIFFERENCE MB Platz auf"
	echo -e "der Platte frei machen, und das Script erneut starten.\n" && exit 1
fi

if [ "$DVDSIZE" -lt "$HDDFREE" ] ; then
	echo -e "\nGenuegend freier Plattenplatz -> $HDDFREE MB <- vorhanden.\n"
fi


# DVD auslesen um den Titel fuer die fertige DVD zu bestimmen.
$DVDBACKUP -i $DVD_ROM -I > $DVD_INFO

DVDTITEL=$(cat $DVD_INFO | grep "DVD-Video information" | cut -d" " -f8- | tr -d [\"])

if [ -z "$DVDTITEL" ] ; then
	NAME="NO_LABEL"
	DATE="$(date +%a-%b-%Y-%H-%M)"
	DVDTITEL=$NAME-$DATE
	echo -e "\n\nKein DVD-Titel erkannt -> DVD-Titel = $DVDTITEL\n"
else
	DVDTITEL=${DVDTITEL//[ ]/_}
	DVDTITEL=${DVDTITEL//Ä/AE}
	DVDTITEL=${DVDTITEL//Ö/OE}
	DVDTITEL=${DVDTITEL//Ü/UE}
	DVDTITEL=${DVDTITEL//ä/ae}
	DVDTITEL=${DVDTITEL//ö/oe}
	DVDTITEL=${DVDTITEL//ü/ue}
	DVDTITEL=${DVDTITEL//ß/SS}
	echo -e "\n\nDVD-Titel = $DVDTITEL\n"
fi


# DVD komplett kopieren - DVD-Struktur (AUDIO_TS,VIDEO_TS) wird erstellt.
echo -e "\nKopiere DVD $DVDTITEL -> auf die Platte ..." 
$NICE $NICE_ARGS $DVDBACKUP -n $DVDTITEL -M -i $DVD_ROM -o $WORKDIR

if [ "$?" = "0" ] ; then
	echo -e "\nDVD $DVDTITEL wurde erfolgreich kopiert.\n"
else
	osd_error_message
	echo -e "\nABBRUCH !\nDVD $DVDTITEL kopieren fehlgeschlagen."
	echo -e "Sorry, hat leider nicht geklappt - eventuell mit einer anderen DVD erneut versuchen.\n" && exit 1
fi


# Manchmal gibt es DVDs die nur den VIDEO_TS bzw. video_ts Ordner beinhalten, fuer diesen
# Fall wird fuer beste Kompatibilitaet der fehlende AUDIO_TS bzw. audio_ts Ordner erstellt. 
if ( [ -d $WORKDIR/$DVDTITEL/VIDEO_TS ] && [ ! -d $WORKDIR/$DVDTITEL/AUDIO_TS ] ) ; then
	mkdir $WORKDIR/$DVDTITEL/AUDIO_TS

		if [ "$?" = "0" ] ; then
			echo -e "\nOrdner AUDIO_TS fuer beste DVD Kompatibilitaet wurde erstellt in:"
			echo -e "$WORKDIR/$DVDTITEL\n"
		fi

elif ( [ -d $WORKDIR/$DVDTITEL/video_ts ] && [ ! -d $WORKDIR/$DVDTITEL/audio_ts ] ) ; then
	mkdir $WORKDIR/$DVDTITEL/audio_ts

		if [ "$?" = "0" ] ; then
			echo -e "\nOrdner audio_ts fuer beste DVD Kompatibilitaet wurde erstellt in:"
			echo -e "$WORKDIR/$DVDTITEL\n"
		fi
fi


# Verschieben der DVD-Struktur (AUDIO_TS, VIDEO_TS) in das Zielverzeichnis (TARGETDIR).
echo -e "\nVerschiebe DVD $DVDTITEL nach ->\n$TARGETDIR ..."
$NICE $NICE_ARGS mv $WORKDIR/$DVDTITEL $TARGETDIR

if [ "$?" = "0" ] ; then
	echo -e "\nDVD $DVDTITEL wurde erfolgreich verschoben nach:\n$TARGETDIR\n"
else
	$WGET -O - -q "$BOXIP/web/message?text=DVD%20$DVDTITEL%20verschieben%20fehlgeschlagen%20-%20nicht%20tragisch%20,%20(%20Details%20dazu%20in%20$LOGFILE%20)&type=2&timeout=15" > /dev/null
	echo -e "\n! DVD $DVDTITEL verschieben fehlgeschlagen - nicht tragisch !"
	echo -e "Einfach manuell z.b: per EMC nach:\n$TARGETDIR verschieben,"
	echo "und zwar deshalb weil für den Fall eines Abbruchs des"
	echo "Scripts, bei einem erneuten Start des Scripts alles unter:"
	echo -e "$WORKDIR geloescht wird.\n"
fi


# Job Ende/Endzeit bei Erfolg bzw. bei Teilerfolg falls nur die DVD-Struktur (AUDIO_TS,VIDEO_TS) erstellt werden konnte.
ENDDATE="$(date +%a.%d.%b.%Y-%H:%M)" && echo -e "\nJOB ENDE -> $ENDDATE\n\n"
$WGET -O - -q "$BOXIP/web/message?text=DVD%20kopieren%20erfolgreich%20beendet%20.%20->%20$ENDDATE&type=1" > /dev/null

exit

 

earlier in older pli images (version 4) and in other images as oatv it works without problems, it starts and then it close first the window and then it runs further in the background, because i need no output only a message if it fails with a message that say have a look in the logfile or if it is ready.

this messages i become with wget commands.

 

but now in openpli-7.2rc it didn't work anymore is i wish.

in spite of i have the line as following at the begin of the script;

$WGET -q -O - $BOXIP/web/remotecontrol?command=352

to close the window, the window doesn't close and the script didn't run in the background as previous.

now the window persits open till the script is complete ready, and in this time you can't do something other with the box, that's not good.

 

i thought now if i rename the script to;

!dvdbackup_to_dvd_complete.sh

then it works correct (it close the window and run in background) but it's exact the same problem.

 

so for what is it good to rename a script to !blabla.sh instead of blabla.sh ?

 

 

regards

Pike


Edited by Pike_Bishop, 20 October 2019 - 18:50.

Receiver: VU Ultimo 4K, Octagon SF8008 4K, Gigablue Quad 4K

Image: OpenPLI-8.3


Re: script in background with hotkey and name !dvdbackup_to_dvd_complete.sh #2 Pike_Bishop

  • Senior Member
  • 1,130 posts

+72
Good

Posted 20 October 2019 - 21:35

sorry wrong section - please move it to;

https://forums.openp...nduser-support/

 

 

thanks

 

regards

Pike


Receiver: VU Ultimo 4K, Octagon SF8008 4K, Gigablue Quad 4K

Image: OpenPLI-8.3


Re: script in background with hotkey and name !dvdbackup_to_dvd_complete.sh #3 Pike_Bishop

  • Senior Member
  • 1,130 posts

+72
Good

Posted 21 October 2019 - 17:22

ok now i think i understand, the exclamation mark so if you rename a script to !blabla.sh is that the cosole window close automatically when the script is ready (successful).

i think also that's a good thing, but something probably with the console is wrong.

 

for longer scripts i can't use anymore a command as following;

$WGET -q -O - $BOXIP/web/remotecontrol?command=352

to close the windows from console at the point that i wish, in fact as well with hotkey as with ppanel.

 

yesterday i testet it with ppanel and in ppanel i must navigate to my script through three windows that i can start it so i need the command;

$WGET -q -O - $BOXIP/web/remotecontrol?command=352

$WGET -q -O - $BOXIP/web/remotecontrol?command=352

$WGET -q -O - $BOXIP/web/remotecontrol?command=352

three times  (as you can see above) to close all windows, but this didn't work too now, instead it starts the script repeatedly (i have seen with command top)

and it is no chance to stop or abort that unless with a restart from the box in telnet.

 

earlier in the old pli-4.0 this was always possible without problems in hotkey and in ppanel too, but now if longer scripts are running and they are written without logging

you can (must) see the output as long as the script is running, because you can't close the windows from console neither with a command in the script as above nor if you press

manually a button on the remote control as exit or ok.

to close the windows is only then possible if the script is successful ready, i think that's a problem for users they want make more with the e2 box like me.

 

please have a look at this problem , what i need is only a possibility to close the window/s to a script as earlier with a command in the script itself and also

the possibility to close these window/s with a keypress on the remote control on exit or/and ok button while the script is running.

 

 

regards

Pike


Edited by Pike_Bishop, 21 October 2019 - 17:24.

Receiver: VU Ultimo 4K, Octagon SF8008 4K, Gigablue Quad 4K

Image: OpenPLI-8.3



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users