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.
    • 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
                                  • W
                                    waterchill @Dr. Bakterius last edited by

                                    @dr-bakterius

                                    Ich habs mit sudo drin und scheint so zu gehen

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

                                      @fastfoot

                                      Also mit ESC komm ich da nich t raus. Ich kann da auch nichts reinschreiben.

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

                                        @waterchill
                                        hm, du scheinst die befehle und konventionen nicht zu kennen.

                                        Mit dem folgenden Befehl versuchst du diese Datei zu bearbeiten, da vi ein editor ist.

                                        sudo vi /etc/sudoers.d/iobroker
                                        

                                        Wenn du die Dokumentation bei ubuntuusers liest, dann steht da sehr deutlich, dass man das Programm visudo
                                        zur Bearbeitung nutzen soll, da man sich ansonsten hier ganz schnell das system zerschießen (also das ganze) kann, falls du einen syntaxfehler einbaust.

                                        Zur Bearbeitung musst du also so aufrufen:

                                        sudo visudo /etc/sudoers.d/iobroker
                                        

                                        Allerdings würde ich an dieser Datei nix verändern.
                                        Wenn dann eine eigene Datei anlegen

                                        sudo visudo /etc/sudoers.d/eigene
                                        

                                        Diese wird dann ebenso in die Abfrage mit eingebunden.

                                        Aber bevor du irgendetwas machst, bitte die Seite
                                        https://wiki.ubuntuusers.de/sudo/Konfiguration/von vorne bis hinten lesen.
                                        Du arbeitest hier an den tiefsten eingeweide von Linux.

                                        Wenn du sagstes funktioniert nicht. was heist das für dich? gibt es eine fehlermeldung.
                                        woran merkst du dann ohne fehlermeldung, das es nicht funktioniert?
                                        weißt du was der befehl eigentlich bedeutet?
                                        /etc/init.d/power_mqtt restart

                                        W 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

                                          Also mit ESC komm ich da nich t raus. Ich kann da auch nichts reinschreiben.

                                          du wirst doch lesen können! dahinter steht :wq!

                                          mit dem ESC beendest du erstmal den Bearbeitungsmodus, mit : kommst du in die Befehlszeile und dann gibst du wq! ein. w=schreibe Änderungen, q= verlasse Editor, !=kümmere dich nicht um read-only.

                                          Ich wundere mich, visudo funktioniert doch auch mit vi? Evtl kannst du auch vim nutzen, aber wenn installiert ruft vi den vim auf

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

                                            @oliverio @fastfoot

                                            Erstmal ganz entspannt 😊 bevor ich solche Sachen probiere, lege ich immer ein Backup an. Das wäre ja fatal, wenn da nix mehr gehen würde in der Bude, da würde die Chefin mir die Hölle heiss machen^^

                                            Also ich habe die Zeile jetzt eingefügt bekommen, dementsprechend kommt jetzt raus:

                                            pi@raspberrypi:~ $ sudo cat /etc/sudoers.d/iobroker       
                                            iobroker ALL=(ALL) ALL
                                            iobroker ALL=(ALL) NOPASSWD: /etc/init.d/power_mqtt *
                                            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 *
                                            

                                            Das war doch das Ziel oder? Trotzdem kann der Befehl aus der iobroker Konsole nicht ohne sudo ausgeführt werden. Meldung die gleiche wie immer. Zwischenzeitlich habe ich auch mal ein reboot gemacht, leider ohne Erfolg.

                                            F OliverIO 2 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            510
                                            Online

                                            31.7k
                                            Users

                                            79.8k
                                            Topics

                                            1.3m
                                            Posts

                                            7
                                            49
                                            3849
                                            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