Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. [gelöst] Befehl als root ausführen oder Rechte ändern?

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    [gelöst] Befehl als root ausführen oder Rechte ändern?

    This topic has been deleted. Only users with topic management privileges can see it.
    • Homoran
      Homoran Global Moderator Administrators @waterchill last edited by

      @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

      Ich habe das Skript nicht geschrieben. Wer sich die ANleitung durchlesen will, die gibt es hier:

      finde da das Skript gar nicht erst

      1 Reply Last reply Reply Quote 0
      • Dr. Bakterius
        Dr. Bakterius Most Active @waterchill last edited by

        @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

        ich möchte eben nur das Skript zu einer bestimmten Zeit ausführen lassen.

        Und warum dann über ioBroker und nicht per cron?

        W 1 Reply Last reply Reply Quote 0
        • F
          fastfoot @Homoran last edited by

          @homoran sagte in Befehl als root ausführen oder Rechte ändern?:

          und das ist IMHO falsch

          für dich zum Lernen 🙂

          root@iobroker:/opt/iobroker# export test=/bin/bash                                                                                                                                                                                                          
          root@iobroker:/opt/iobroker# echo basename $test                                                                                                                                                                                                            
          basename /bin/bash                                                                                                                                                                                                                                          
          root@iobroker:/opt/iobroker# echo 'basename $test'                                                                                                                                                                                                          
          basename $test                                                                                                                                                                                                                                              
          root@iobroker:/opt/iobroker# echo `basename $test`                                                                                                                                                                                                          
          bash                                                                                                                                                                                                                                                        
          root@iobroker:/opt/iobroker#              
          
          Homoran 1 Reply Last reply Reply Quote 1
          • Homoran
            Homoran Global Moderator Administrators @fastfoot last edited by Homoran

            @fastfoot sagte in Befehl als root ausführen oder Rechte ändern?:

            für dich zum Lernen

            Danke!
            🤔

            aber das mit dem kill wäre dann:

            pi@raspberrypi:/opt/iobroker $ echo basename `test`
            basename
            
            F 1 Reply Last reply Reply Quote 0
            • W
              waterchill @Dr. Bakterius last edited by

              @dr-bakterius

              Bin ich grad dabei. Müsste dann so passen oder?

              */2 16-20 * * * sudo /etc/init.d/power_mqtt restart
              

              Jede zweite Minute von 16-20 Uhr täglich

              F Dr. Bakterius 2 Replies Last reply Reply Quote 0
              • liv-in-sky
                liv-in-sky last edited by

                was macxht dieses script überhaupt ? installiert das ein bash script als service ? oder lieg ich da falsch

                W 1 Reply Last reply Reply Quote 0
                • F
                  fastfoot @Homoran last edited by

                  @homoran sagte in Befehl als root ausführen oder Rechte ändern?:

                  aber das mit dem kill wäre dann:

                  das was zwischen den ticks steht wird ausgeführt und das Ergebnis zurückgegeben. es wird also get_pid ausgeführt und gibt eine PID zurück. Die wird dann gekillt

                  liv-in-sky 1 Reply Last reply Reply Quote 0
                  • liv-in-sky
                    liv-in-sky @fastfoot last edited by

                    @fastfoot aber dieses kill wird mit iobroker ausgeführt (wurde ja so bestimmt im script unter user) - der darf doch das nicht - da müßte kill in die sudoers datei für iobroker ?

                    1 Reply Last reply Reply Quote 0
                    • F
                      fastfoot @waterchill last edited by

                      @waterchill der Ansatz mit sudoers war ja gar nicht so schlecht. Kannst du mal das Ergebnis von cat /etc/sudoers.d/iobroker posten?

                      W 1 Reply Last reply Reply Quote 0
                      • W
                        waterchill @liv-in-sky last edited by

                        @liv-in-sky

                        Also Grundlegend geht es um folgendes. Das ganze liest über ANT+ aus einem Pulsmesser (Brustgurt) den Puls aus schiebt das in eine mqtt und dann rüber zum iobroker mqtt Server. Damit kann ich bei Rad Indoor übern Puls zwei Xiaomi Lüfter steuern. Je höher der Puls desto mehr Drehzahl. Das ganze läuft auch wunderbar, die Lüfter hab ich so eingestellt, dass pro 10 mehr Puls 10% mehr Speed. Der Haken an der Sache ist, manchmal hängt sich das Skript auf und dann friert er auf einer Herzfrequenzzahl ein z.B. 135 oder so. Dementsprechend laufen die Lüfter dann aber regeln nicht mehr. Abhilfe: Skript Restart. Das gleiche Spielchen beginnt vor dem Sport, man muss das Skript restarten, damit das läuft. Da hab ich mir gedacht warum nicht einfach alle 2 min von 16-20 das Skript automatisch restarten lassen. So braucht man nichts mehr machen. Scheinbar geht das irgendwie in einen Sleepmode oder sowas. Ändern sich die Herzfrequenz häufig z.B. bei einem Workout dass mal langsam und schnell geht hängt sich so gut wie nie auf. Anders schauts aus wenn man konstant mal ne Stunde fährt. Da isses häufiger. Ja perfekt is die Lösung nicht, aber mir fällt nichts anderes ein.

                        liv-in-sky 1 Reply Last reply Reply Quote 0
                        • liv-in-sky
                          liv-in-sky @waterchill last edited by

                          @waterchill

                          interessant - könntest du dein script nicht als service installieren auf linux ebene - dann kannst du mit systemctl restart ... usw arbeiten

                          1 Reply Last reply Reply Quote 0
                          • W
                            waterchill @fastfoot last edited by

                            @fastfoot

                            Interessant, das Ergebnis ist wie folgt:

                            pi@raspberrypi:~ $ cat /etc/sudoers.d/iobroker
                            cat: /etc/sudoers.d/iobroker: Keine Berechtigung
                            

                            Ich habe folgendes Eingetragen:

                            # User privilege specification
                            root    ALL=(ALL:ALL) ALL
                            iobroker        ALL= /etc/init.d/power_mqtt
                            
                            F 1 Reply Last reply Reply Quote 0
                            • F
                              fastfoot @waterchill last edited by

                              @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

                              @fastfoot

                              Interessant, das Ergebnis ist wie folgt:

                              pi@raspberrypi:~ $ cat /etc/sudoers.d/iobroker
                              cat: /etc/sudoers.d/iobroker: Keine Berechtigung
                              

                              Ich habe folgendes Eingetragen:

                              # User privilege specification
                              root    ALL=(ALL:ALL) ALL
                              iobroker        ALL= /etc/init.d/power_mqtt
                              

                              das sollte man so nicht machen, besser ist eine Datei anzulegen. probiere das cat mit sudo, es geht darum ob das file überhaupt schon existiert

                              W 1 Reply Last reply Reply Quote 0
                              • W
                                waterchill @fastfoot last edited by

                                @fastfoot

                                pi@raspberrypi:~ $ sudo cat /etc/sudoers.d/iobroker
                                iobroker ALL=(ALL) ALL
                                iobroker ALL=(ALL) NOPASSWD: /sbin/shutdown
                                iobroker ALL=(ALL) NOPASSWD: /sbin/halt
                                iobroker ALL=(ALL) NOPASSWD: /sbin/poweroff
                                iobroker ALL=(ALL) NOPASSWD: /sbin/reboot
                                iobroker ALL=(ALL) NOPASSWD: /bin/systemctl start
                                iobroker ALL=(ALL) NOPASSWD: /bin/systemctl stop
                                iobroker ALL=(ALL) NOPASSWD: /bin/mount
                                iobroker ALL=(ALL) NOPASSWD: /bin/umount
                                iobroker ALL=(ALL) NOPASSWD: /usr/bin/systemd-run
                                iobroker ALL=(ALL) NOPASSWD: /usr/bin/apt-get
                                iobroker ALL=(ALL) NOPASSWD: /usr/bin/apt
                                iobroker ALL=(ALL) NOPASSWD: /usr/bin/dpkg
                                iobroker ALL=(ALL) NOPASSWD: /usr/bin/make
                                iobroker ALL=(ALL) NOPASSWD: /bin/ping
                                iobroker ALL=(ALL) NOPASSWD: /sbin/setcap
                                iobroker ALL=(ALL) NOPASSWD: /usr/bin/vcgencmd
                                iobroker ALL=(ALL) NOPASSWD: /bin/cat
                                iobroker ALL=(ALL) NOPASSWD: /bin/df
                                iobroker ALL=(ALL) NOPASSWD: /sbin/ldconfig
                                ALL ALL=NOPASSWD: /bin/systemctl start iobroker
                                ALL ALL=NOPASSWD: /bin/systemctl stop iobroker
                                ALL ALL=NOPASSWD: /bin/systemctl restart iobroker
                                ALL ALL=(iobroker) NOPASSWD: /usr/local/bin/node /opt/iobroker/node_modules/iobroker.js-controller/iobroker.js *
                                
                                F 1 Reply Last reply Reply Quote 0
                                • F
                                  fastfoot @waterchill last edited by

                                  @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

                                  @fastfoot

                                  pi@raspberrypi:~ $ sudo cat /etc/sudoers.d/iobroker
                                  iobroker ALL=(ALL) ALL
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/shutdown
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/halt
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/poweroff
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/reboot
                                  iobroker ALL=(ALL) NOPASSWD: /bin/systemctl start
                                  iobroker ALL=(ALL) NOPASSWD: /bin/systemctl stop
                                  iobroker ALL=(ALL) NOPASSWD: /bin/mount
                                  iobroker ALL=(ALL) NOPASSWD: /bin/umount
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/systemd-run
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/apt-get
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/apt
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/dpkg
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/make
                                  iobroker ALL=(ALL) NOPASSWD: /bin/ping
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/setcap
                                  iobroker ALL=(ALL) NOPASSWD: /usr/bin/vcgencmd
                                  iobroker ALL=(ALL) NOPASSWD: /bin/cat
                                  iobroker ALL=(ALL) NOPASSWD: /bin/df
                                  iobroker ALL=(ALL) NOPASSWD: /sbin/ldconfig
                                  ALL ALL=NOPASSWD: /bin/systemctl start iobroker
                                  ALL ALL=NOPASSWD: /bin/systemctl stop iobroker
                                  ALL ALL=NOPASSWD: /bin/systemctl restart iobroker
                                  ALL ALL=(iobroker) NOPASSWD: /usr/local/bin/node /opt/iobroker/node_modules/iobroker.js-controller/iobroker.js *
                                  

                                  ok, sudo vi /etc/sudoers.d/iobroker

                                  dort in die 2te Zeile: iobroker ALL=(ALL) NOPASSWD: /etc/init.d/power_mqtt *

                                  vi beenden mit ESC-Taste, dann :wq!

                                  aus Blockly rufst du jetzt das script mit sudo /etc/init.d/power_mqtt auf

                                  die Änderungen in /etc/sudoers rückgängig machen!

                                  W F 2 Replies Last reply Reply Quote 0
                                  • OliverIO
                                    OliverIO @waterchill last edited by OliverIO

                                    @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

                                    Moin,

                                    ich kämpfe seit heute heute früh mit einem Problem. Ich möchte folgenden Befehl über blockly ausführen:

                                    /etc/init.d/power_mqtt restart

                                    Das Problem ist, der Befehl geht nur über sudo und sudo ist im Terminal nicht möglich. Habe folgendes versucht über ssh KOnsole des users pi:

                                    sudo chmod -v 777 power_mqtt

                                    -> kein Erfolg

                                    dann:

                                    sudo chown iobroker power_mqtt

                                    -> kein Erfolg

                                    dann:

                                    sudo visudo /etc/sudoers

                                    dort entsprechend eingetragen:

                                    iobroker ALL= /etc/init.d/power_mqtt

                                    -> kein Erfolg

                                    Nun bin ich mit meinem Wissen am Ende. Hat jemand einen Tipp?

                                    @waterchill

                                    Ich glaube bei den sudoers hast du noch einen fehler
                                    müsse es nicht so heissen:

                                    iobroker ALL=(ALL) NOPASSWD: /etc/init.d/power_mqtt
                                    

                                    ob es funktioniert, kannst du selbst auf der shell testen, in dem du dich als
                                    iobroker anmeldest mit

                                    sudo -u iobroker bash
                                    /etc/init.d/power_mqtt restart
                                    

                                    https://wiki.ubuntuusers.de/sudo/Konfiguration/

                                    W 1 Reply Last reply Reply Quote 0
                                    • W
                                      waterchill @OliverIO last edited by

                                      @oliverio

                                      Habe es jetzt so rein, funktioniert leider auch nicht 😞

                                      # User privilege specification
                                      root    ALL=(ALL:ALL) ALL
                                      iobroker ALL=(ALL) NOPASSWD: /etc/init.d/power_mqtt
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • W
                                        waterchill @fastfoot last edited by waterchill

                                        @fastfoot said in Befehl als root ausführen oder Rechte ändern?:

                                        sudo vi /etc/sudoers.d/iobroker

                                        Wenn ich das so ausführe, dann kann ich da drin nichts ändern, unten steht dann {readonly} ich komm dann auch nimmer raus aus dem Teil. Terminal muss dann beendet werden. Scheinbar wird die Datei gerade verwendet oder so

                                        OliverIO 1 Reply Last reply Reply Quote 0
                                        • F
                                          fastfoot @fastfoot last edited by

                                          @waterchill

                                          @fastfoot sagte in Befehl als root ausführen oder Rechte ändern?:
                                          vi beenden mit ESC-Taste, dann :wq!

                                          W 1 Reply Last reply Reply Quote 0
                                          • Dr. Bakterius
                                            Dr. Bakterius Most Active @waterchill last edited by

                                            @waterchill sagte in Befehl als root ausführen oder Rechte ändern?:

                                            */2 16-20 * * * sudo /etc/init.d/power_mqtt restart
                                            

                                            Ja, aber statt sudo root.

                                            W 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            936
                                            Online

                                            31.7k
                                            Users

                                            79.7k
                                            Topics

                                            1.3m
                                            Posts

                                            7
                                            49
                                            3838
                                            Loading More Posts
                                            • Oldest to Newest
                                            • Newest to Oldest
                                            • Most Votes
                                            Reply
                                            • Reply as topic
                                            Log in to reply
                                            Community
                                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                            The ioBroker Community 2014-2023
                                            logo