v17 Script when kodi shutdown - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33) +--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111) +---- Forum: Raspberry Pi (https://forum.kodi.tv/forumdisplay.php?fid=166) +---- Thread: v17 Script when kodi shutdown (/showthread.php?tid=317441) |
Script when kodi shutdown - Assomnia - 2017-06-29 Hi there, I have a bash script I would like to run as soon as Kodi is shutdown. Is there any way to manage that ? I'm running a device without keyboard so basically the script is just a bash that start and allow to use button connected to the GPIO to launch program. Thanks guys RE: Script when kodi shutdown - DaVu - 2017-06-29 For Libre- or OpenELEC there is the shutdown.sh file where you are also able to execute additional scripts. See: https://wiki.libreelec.tv/index.php?title=Autostart.sh the same will work OpenELEC. So depending on your shutdown option (let´s assume it´s "poweroff") you have to enter the commands which should be executed before the Pi shuts down. Example: Code: case "$1" in that will execute the script "script.sh" if you "poweroff" the Pi. Not sure if that will work for OSs like raspbian. RE: Script when kodi shutdown - Assomnia - 2017-06-29 Hey thanks for answering. Do I have to create this file or it should be there ? EDIT : Well I created the file here : /home/pi/.config/shutdown.sh I wrote this in : Code: #!/bin/bash Doesn't work :/ RE: Script when kodi shutdown - DaVu - 2017-06-29 If you would have read the wiki I linked, you could have answered your question yourself: If you are on LibreELEC or OpenELEC you have to create the file under: /storage/.config If you are not on one of those OSs, this won´t work. RE: Script when kodi shutdown - Assomnia - 2017-06-29 There we go... Sorry man didn't see that I was wondering... There was no storage what so ever ^^ Anything I could do then to launch a .sh when shutdown Kodi ? RE: Script when kodi shutdown - DaVu - 2017-06-29 What about to mention the OS you are using? As this would help most for the first steps. RE: Script when kodi shutdown - Assomnia - 2017-06-29 Sorry sure. I'm running Raspbian, with kodi and emulationstation installed manually. I put the pi in a psp shell and the buttons are attached to the GPIO Basically when I boot I would like a script I wrote to start (couldn't manage the script to start after the boot actually. The script works well tho'). Once the script starts you just press a button on the PSP and the software start. I'd like that when exiting the soft, the script start again. Example : I start my psp. The script start. I launch Kodi by pressing a button. I exit Kodi the script start again. I press on a other button, emulationstation is starting. I exit emulationstation the script starts again etc... RE: Script when kodi shutdown - DaVu - 2017-06-29 start script on boot: https://raspberrypi.stackexchange.com/questions/8734/execute-script-on-start-up the first answer mentions 2 option to run a scipt on startup. Choose which one will fit best for you. Both will work. For the shutdown and start the script again...what does exactly happen if you press the button which starts kodi? Does it trigger some script/command to run kodi? Could you show that please? RE: Script when kodi shutdown - Assomnia - 2017-06-29 This is the script I'm talking about : Code: #!/bin/bash So if I press Esc on the keyboard or the Triangle button on the PSP it starts Kodi. That's it . Now when I exit Kodi how couyld I possibly run the script above again ? RE: Script when kodi shutdown - Assomnia - 2017-06-29 I checked your link... and I have a problem : Warning - its important you test your script first and make sure it doesn't need a user to provide a response, press "y" or similar, because you may find it hangs the raspberry pi on boot waiting for a user (who's not there) to do something! So this is why it's not working. Because my script is based on answer from the user.... What now ? :'( EDIT : Crontab ? RE: Script when kodi shutdown - Assomnia - 2017-06-29 Find the solution I edited this file : sudo nano /etc/profile and added my script at the end. After each login it is launching the script. As in raspbian there is the auto login at boot. The script starts Now just have to find out how to start the script again when I exit Kodi EDIT : Found a solution. It's probably not the best one but I changed the code to this : Code: #!/bin/bash So after the soft has started the script starts as well in the background. Better than nothing RE: Script when kodi shutdown - DaVu - 2017-06-29 I thought about some functions and don't let the script exit after boot. I'm just on my mobile atm so I'll provide something later in the evening RE: Script when kodi shutdown - DaVu - 2017-06-29 First and I know it's nitpicking ...don't name a bash script with *.sh as an extension. "filename.sh" will assume your are writing a "sh-script", which is different from "bash-scripts". Just don't use an extension for bash scripts at all. Just name it "filename" ... nothing else. Example using functions: explanation....functions are codeblocks inside scripts which can be called from everywhere inside the script....again and again!! Code: #!/bin/bash This could be an example how the script could work with functions. The script starts at the top, echoing all what you wrote at the top. Then it will read all the functions, but doing nothing with them as you didn't call them yet. Then it will read the command "input" at the bottom and then the input-function will be called and the magic happens . It will read your input an In "case" you will press the button for kodi, it will call the "start_kodi"-function and kodi will run. After you exit kodi (the script will still run as it waits for the termination of Kodi to go further) it will call the input-function again and you are in your "case" again. The same will take place for emulationstation. Press a specific key for that application and after exiting it, the input-function will be called and you are in the "case" again and the script waits for a specific input. You could understand all the above as a big loop which will run as long as you exit it if the case won't work those Code: $'\e' Code: input() { I couldn't runtime test this script and maybe it's a bit hacky . But maybe it gives you another idea how things might be done. So you don't need to care how to call the script multiple times as that would cause multiple subprocesses probably which I would try to avoid if I were you . That script hasn't the option to exit. Maybe you are able to map "x" to the "X"-Button for exit and add: Code: 'x') before the "*)" part at the case-statement. Hope it helps. Cheers Edit: Btw....don't use just "exit" to exit a script. Use "exit 0" instead. That will mean that the script run successfully. If you will ever write other scripts for your systems, you might need different exit-statuses and explain (inside the script with comments) what the specific exit-status could mean. Assume some command didn't run or you check for something which might fail (probably if a folder exists), then you should exit the script with anything else beside "0" (zero). for example "exit 1", or "exit 2" and so on. Everything else beside "0" will mean that the script exits with an issue or something didn't worked as expected or how it should. See that for example: https://github.com/LibreELEC/LibreELEC.tv/blob/master/packages/sysutils/busybox/scripts/getedid That's a script I wrote some time ago where I have explained all the exit-statuses at top. RE: Script when kodi shutdown - Assomnia - 2017-06-30 Hey there ! That was very well explain thank you very much for that. I will work on it again, because you are right, multiple process is probably not the best. Thanks again I will try that. |