RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    shell scripting topic

    Scheduled Pinned Locked Moved Ideas and Development
    shellshell scriptprogramming
    191 Posts 10 Posters 76.9k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • meleuM
      meleu @cyperghost
      last edited by

      @cyperghost

      So again - I'm looking forward in v1.7
      two versions

      1. Mausberry shutdown script without inotify
      2. Mausberry shutdown script with inotify

      I would like to emphasize the difference between versions this way:

      1. Shutdown script checking for a change in that file every single second.
      2. Shutdown script that does nothing until that file changes.

      :-)

      • Useful topics
      • joystick-selection tool
      • rpie-art tool
      • achievements I made
      1 Reply Last reply Reply Quote 1
      • cyperghostC
        cyperghost
        last edited by cyperghost

        @meleu I will raise Garbage PID detector to v1.1 with your RegEx findings.
        thx mate

        @meleu PID detector 1.1 is ready. Sorry I used emupid instead of emu_command
        It now works 100% flawless ...

        1 Reply Last reply Reply Quote 1
        • cyperghostC
          cyperghost
          last edited by

          @meleu
          I pushed the mausberry shutdown script to 1.55 - all kudos to you.
          But I want to avoid different usecased. Because some use 1.5 now.
          So I think it doesn't matter if there is a v1.7 with better coding style or a v1.55 with more if-then clauses.
          All contain your genoius RegEx sniplet that will work in all cases! I hope it is okay for you. In the sake for the best user experience we can give.

          meleuM 1 Reply Last reply Reply Quote 0
          • meleuM
            meleu @cyperghost
            last edited by

            @cyperghost said in shell scripting topic:

            I hope it is okay for you.

            C'mon man! Every line of code I post in this forum can be considered public domain. ;-)

            Use it the way you want!

            • Useful topics
            • joystick-selection tool
            • rpie-art tool
            • achievements I made
            cyperghostC 1 Reply Last reply Reply Quote 1
            • cyperghostC
              cyperghost @meleu
              last edited by

              @meleu okay PD-meleu

              1 Reply Last reply Reply Quote 0
              • meleuM
                meleu @cyperghost
                last edited by

                @cyperghost said in Mausberry Shutdown Script Doesn't Save Metadata:

                I think so, but I'm pretty sure that your solution (ScummVM fix) is already in usage by @hansolo77

                Your posted script is still using this:

                emupid="$(pgrep -f "${emupid%% *}")"
                

                Which gets only bash on ScumVM case. Maybe you want to change it to v1.56 and use

                emupid="$(pgrep -f "$emupid")"
                
                • Useful topics
                • joystick-selection tool
                • rpie-art tool
                • achievements I made
                cyperghostC 2 Replies Last reply Reply Quote 1
                • cyperghostC
                  cyperghost @meleu
                  last edited by

                  @meleu Thx my friend

                  1 Reply Last reply Reply Quote 0
                  • cyperghostC
                    cyperghost @meleu
                    last edited by cyperghost

                    @meleu About the inotify thing.
                    Do you have any clue why the GPIO signal is not detected? At first it works only if you have root access - but I'm pretty sure you already know. As far as I looked to v 1.6 of your code it should work without any problem.

                    If there are any issues you can try to use GPIO control

                    If you watch Pin26 for a switch via GPIO control just place file 26 (without .sh!) to /etc/gpio-scripts/ and give the echo 1 > command in this file.

                    26

                    #!/bin/bash
                    #this is the GPIO pin connected to the lead on switch labeled OUT
                    GPIOpin1=23
                    echo "1" > /sys/class/gpio/gpio$GPIOpin1/value
                    meleuM 1 Reply Last reply Reply Quote 0
                    • meleuM
                      meleu @cyperghost
                      last edited by

                      @cyperghost said in shell scripting topic:

                      @meleu About the inotify thing.
                      Do you have any clue why the GPIO signal is not detected?

                      it's pretty hard to test things without the respective thing! :-)

                      I've made some tests with @lostless (I was giving instructions via IRC) and he was able to turn off his raspi with echo 1 > /sys..., but not with the switch pressing.

                      Then I'm pretty sure that my method works as expected, but there's something in the Mausberry switch that I'm not able to diagnose...

                      • Useful topics
                      • joystick-selection tool
                      • rpie-art tool
                      • achievements I made
                      cyperghostC 1 Reply Last reply Reply Quote 0
                      • cyperghostC
                        cyperghost @meleu
                        last edited by cyperghost

                        @meleu I also have no clue why the thing won't catch up.
                        I tried to load inotifywait throug rc.local and it worked.
                        As I changed the monitored file I get a note and the process inotifywait finished.

                        I've made some tests with @lostless (I was giving instructions via IRC) and he was able to turn off his raspi with echo 1 > /sys..., but not with the switch pressing.

                        It would be interesting to see what is happening internal through the GPIO if you press a button. Maybe it's better do use an more "advanced" bibliothek like wiring pi. Because with wPi you can detect flanks. But that's the suggestion I made by using an driver to detect keypresses.

                        1 Reply Last reply Reply Quote 0
                        • meleuM
                          meleu
                          last edited by

                          @cyperghost Just to share some bash coding knowledge, I would like to make some comments about your bash coding philosophy :)

                          • the bash scripting language is an interpreted programming language
                          • if you google about "compiled vs intepreted language" and you realize that interpreted languaged tends to be slower.
                          • type man bash on your terminal, go the end of the bash man page and look at the first sentence in the BUGS section. ;-)

                          Why is @meleu trying to convince me that bash is slow if he loves bash?

                          Well, I love bash because it is widely used. If it wasn't for that I would have migrated to zsh (which is even more powerfull), but let's not go deep into this nerdy stuff...

                          I'm talking all those things because of your very good practice of checking if everything is really fine before running a command. In other languages, if you don't do these checkings, the program may crash. But when coding bash scripts (or any other shell language) it's a better yet practice to take advantage of every chance you have to optimize things.

                          I'm talking specifically for this part:

                          if [[ -e "/dev/shm/runcommand.info" ]]; then
                              emupid="$(sed -n 4p /dev/shm/runcommand.info | tr -d '\\"' | tr '^$[]*.()|+?{}' '.')"
                              emupid="$(pgrep -f "$emupid")" 
                          fi
                          
                          if [ "$emupid" ]; then
                              kill $emupid && sleep 9
                          fi
                          

                          You're making bash check if the runcommand.info exists, but sed already does that.
                          You're getting the emulator's PID with pgrep, but pkill won't kill anything if there isn't a process matching the pattern.

                          That's why I would change all the logic above with this here:

                          emupid="$(sed -n 4p /dev/shm/runcommand.info | tr -d '\\"' | tr '^$[]*.()|+?{}' '.')"
                          [[ -n "$emu_command" ]] && pkill -f "${emupid}" && sleep 9
                          

                          That's it. :-)

                          Cheers.

                          • Useful topics
                          • joystick-selection tool
                          • rpie-art tool
                          • achievements I made
                          lilbudL 1 Reply Last reply Reply Quote 0
                          • lilbudL
                            lilbud @meleu
                            last edited by

                            @meleu Me after reading that whole post
                            0_1501613667625_b69a7a0f-c51a-4d8b-ab8e-27144bb02dbe-image.png

                            Creator of the Radiocade: https://retropie.org.uk/forum/topic/6077/radiocade

                            Backlog: http://backloggery.com/lilbud

                            meleuM 1 Reply Last reply Reply Quote 0
                            • meleuM
                              meleu @lilbud
                              last edited by meleu

                              @lilbud this topic was created exactly to avoid this reaction on other people's topics. :-)

                              • Useful topics
                              • joystick-selection tool
                              • rpie-art tool
                              • achievements I made
                              1 Reply Last reply Reply Quote 0
                              • cyperghostC
                                cyperghost
                                last edited by

                                @lilbud You're welcome to ask and post things affecting bash :)

                                lilbudL 1 Reply Last reply Reply Quote 0
                                • lilbudL
                                  lilbud @cyperghost
                                  last edited by

                                  @cyperghost OK, I have very little experience with code and zero experience with bash.

                                  Where in the hell do I start?

                                  Creator of the Radiocade: https://retropie.org.uk/forum/topic/6077/radiocade

                                  Backlog: http://backloggery.com/lilbud

                                  meleuM cyperghostC 2 Replies Last reply Reply Quote 0
                                  • meleuM
                                    meleu @lilbud
                                    last edited by

                                    @lilbud at prompt. Type echo "Hello World". ;-)

                                    • Useful topics
                                    • joystick-selection tool
                                    • rpie-art tool
                                    • achievements I made
                                    lilbudL cyperghostC 2 Replies Last reply Reply Quote 1
                                    • lilbudL
                                      lilbud @meleu
                                      last edited by

                                      @meleu So...echo is like a print command?

                                      Creator of the Radiocade: https://retropie.org.uk/forum/topic/6077/radiocade

                                      Backlog: http://backloggery.com/lilbud

                                      1 Reply Last reply Reply Quote 1
                                      • cyperghostC
                                        cyperghost @lilbud
                                        last edited by

                                        @lilbud
                                        You start with

                                        cd ~
                                        touch hello.sh && chmod +x hello.sh && echo 'echo -e "Hello World\nThis is my 1. code in bash"' > hello.sh
                                        ./hello.sh
                                        
                                        meleuM 1 Reply Last reply Reply Quote 1
                                        • cyperghostC
                                          cyperghost @meleu
                                          last edited by

                                          @meleu Upss..
                                          Are we not in lesson #2?

                                          1 Reply Last reply Reply Quote 0
                                          • meleuM
                                            meleu @cyperghost
                                            last edited by

                                            @cyperghost Me after reading your tutorial:
                                            confused

                                            • Useful topics
                                            • joystick-selection tool
                                            • rpie-art tool
                                            • achievements I made
                                            lilbudL 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                                            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.