Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Remote Raspberry herunterfahren

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    Remote Raspberry herunterfahren

    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tiego last edited by

      Hallo,
      ich habe im Forum folgendes Script zum Herunterfahren eines Remote RPIs gefunden.

      on({id: 'admin.0.Octoprint_Shutdown', change: "ne"}, async function (obj) {
          var value = obj.state.val;
          var oldValue = obj.oldState.val;
          if ((obj.state ? obj.state.val : "") == true) {
              setStateDelayed('admin.0.Octoprint_Shutdown', false, false, parseInt(((0) || "").toString(), 10), false);
              node_ssh = require('node-ssh');
              var ssh = new node_ssh();
              ssh.connect({
                  host: '192.168.170.25',
                  username: 'pi',
                  password: 'xyz'
              }).then(() => {
                  ssh.execCommand("sudo shutdown");
              })
      
          }
      });
      

      leider funktioniert es nicht.
      das Packet "node_ssh" habe ich beim Javascript Kontroller hinzugefügt und neu gestartet, leider ohne erfolg. Ich erhalte immer folgende Fehler im Log.

      javascript.0
      	2021-11-15 21:40:32.984	error	Cannot install npm packet: node_ssh
      javascript.0
      	2021-11-15 21:40:32.983	error	Cannot install node_ssh: 1
      javascript.0
      	2021-11-15 21:40:32.963	error	npm ERR! A complete log of this run can be found in: npm ERR! /home/iobroker/.npm/_logs/2021-11-15T20_40_32_949Z-debug.log
      javascript.0
      	2021-11-15 21:40:32.949	error	npm ERR! 404 tarball, folder, http url, or git url.
      javascript.0
      	2021-11-15 21:40:32.947	error	ERR! 404 Not Found - GET https://registry.npmjs.org/node_ssh - Not found npm ERR! 404 npm ERR! 404 'node_ssh@latest' is not in the npm registry. npm ERR! 404 You should bug the author to publish it (or use the name yourself!) npm ERR! 404 npm ERR! 404 Note that you can also install from a
      javascript.0
      	2021-11-15 21:40:32.945	error	npm
      javascript.0
      	2021-11-15 21:40:32.934	error	ERR! code E404
      javascript.0
      	2021-11-15 21:40:32.931	error	npm
      javascript.0
      	2021-11-15 21:40:30.810	error	Cannot install node_ssh: 1
      javascript.0
      	2021-11-15 21:40:30.796	error	npm ERR! A complete log of this run can be found in: npm ERR! /home/iobroker/.npm/_logs/2021-11-15T20_40_30_782Z-debug.log
      javascript.0
      	2021-11-15 21:40:30.794	error	
      javascript.0
      	2021-11-15 21:40:30.781	error	ERR! 404 Not Found - GET https://registry.npmjs.org/node_ssh - Not found npm ERR! 404 npm ERR! 404 'node_ssh@latest' is not in the npm registry. npm ERR! 404 You should bug the author to publish it (or use the name yourself!) npm ERR! 404 npm ERR! 404 Note that you can also install from a npm ERR! 404 tarball, folder, http url, or git url.
      javascript.0
      	2021-11-15 21:40:30.779	error	npm
      javascript.0
      	2021-11-15 21:40:30.770	error	ERR! code E404
      javascript.0
      	2021-11-15 21:40:30.768	error	
      javascript.0
      	2021-11-15 21:40:30.766	error	npm
      

      könntet Ihr mir bitte helfen das Problem zu lösen? Ich steh seit über 2h auf der Leitung
      danke euch.

      Thomas Braun mickym 2 Replies Last reply Reply Quote 0
      • Thomas Braun
        Thomas Braun Most Active @tiego last edited by

        @tiego
        Wie eingetragen?
        Das Modul nennt sich wohl node-ssh

        T 1 Reply Last reply Reply Quote 0
        • T
          tiego @Thomas Braun last edited by

          @thomas-braun sagte in Remote Raspberry herunterfahren:

          as Modul nennt sich wohl node-ss

          hallo, danke.
          ja das Module ist node-ssh
          leider steht dazu im log nichts, vorhin hatte ich nur zum testetn den - mit _ ersetzt.

          Thomas Braun 1 Reply Last reply Reply Quote 0
          • Thomas Braun
            Thomas Braun Most Active @tiego last edited by

            @tiego
            Was steht denn im Log, wenn das Modul mit Bindestrich geschrieben wird?

            T 1 Reply Last reply Reply Quote 0
            • T
              tiego @Thomas Braun last edited by

              @thomas-braun
              leider nichts, es bleibt leer

              Thomas Braun 1 Reply Last reply Reply Quote 0
              • Thomas Braun
                Thomas Braun Most Active @tiego last edited by

                @tiego Keine Meldung ist in der Regel positiv. Wird wohl dann funktionieren.

                T 1 Reply Last reply Reply Quote 0
                • T
                  tiego @Thomas Braun last edited by

                  @thomas-braun leider nicht,
                  im Log, steht wenn ich das script starte:

                  Zeit
                  	
                  Nachricht
                  javascript.0
                  	2021-11-15 22:08:07.957	error	at processImmediate (internal/timers.js:461:21)
                  javascript.0
                  	2021-11-15 22:08:07.956	error	at Immediate.<anonymous> (/opt/iobroker/node_modules/iobroker.js-controller/lib/adapter.js:5706:41)
                  javascript.0
                  	2021-11-15 22:08:07.956	error	at Object.stateChange (/opt/iobroker/node_modules/iobroker.javascript/main.js:530:29)
                  javascript.0
                  	2021-11-15 22:08:07.956	error	at Object.callback (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1087:38)
                  javascript.0
                  	2021-11-15 22:08:07.955	error	at Object.<anonymous> (script.js.common.Octoprint_shutdown:7:19)
                  javascript.0
                  	2021-11-15 22:08:07.949	error	script.js.common.Octoprint_shutdown: TypeError: node_ssh is not a constructor
                  
                  Homoran Chaot 2 Replies Last reply Reply Quote 0
                  • Homoran
                    Homoran Global Moderator Administrators @tiego last edited by

                    @tiego sagte in Remote Raspberry herunterfahren:

                    im Log, steht wenn ich das script starte:

                    @tiego sagte in Remote Raspberry herunterfahren:

                    at Object.<anonymous> (script.js.common.Octoprint_shutdown:7:19)

                    und was steht da im Script?

                    T 1 Reply Last reply Reply Quote 0
                    • Chaot
                      Chaot @tiego last edited by Chaot

                      @tiego
                      Sieht bei mir so aus:

                      on({id: 'javascript.0.Vis.MonitorReload', val: true}, function (obj) {
                        var value = obj.state.val;
                        var oldValue = obj.oldState.val;
                      
                      node_ssh = require('node-ssh');
                      
                      ssh = new node_ssh();
                      
                      ssh.connect({
                      
                        host: '192.168.8.15',
                      
                        username: '***i',
                      
                        password: '****'
                      
                      }).then(() => {
                      
                        ssh.execCommand("DISPLAY=:0 xdotool key F5");
                      
                      })
                      });
                      

                      Ist bei Zeile 7 anders ausgeführt (ohne var)

                      T 1 Reply Last reply Reply Quote 0
                      • T
                        tiego @Homoran last edited by

                        @homoran
                        node_ssh = require('node-ssh');

                        Homoran 1 Reply Last reply Reply Quote 0
                        • T
                          tiego @Chaot last edited by

                          @chaot ???

                          1 Reply Last reply Reply Quote 0
                          • Homoran
                            Homoran Global Moderator Administrators @tiego last edited by

                            @tiego sagte in Remote Raspberry herunterfahren:

                            @homoran
                            node_ssh = require('node-ssh');

                            das ist nicht Zeile 7

                            T 1 Reply Last reply Reply Quote 0
                            • T
                              tiego @Homoran last edited by

                              @homoran
                              hallo, doch. oder wird die erste zeile als 0 gezählt?

                              1 Reply Last reply Reply Quote 0
                              • Homoran
                                Homoran Global Moderator Administrators last edited by

                                @tiego sagte in Remote Raspberry herunterfahren:

                                @homoran
                                hallo, doch. oder wird die erste zeile als 0 gezählt?

                                das ist dein gepostetes Skript:
                                ausnahmsweise als Screenshot
                                Screenshot_20211116-204749_Firefox.jpg

                                in zeile 7 steht was anderes

                                1 Reply Last reply Reply Quote 0
                                • mickym
                                  mickym Most Active @tiego last edited by mickym

                                  @tiego Ehrlich gesagt verstehe ich nicht warum hier so ein Aufwand betrieben wird?

                                  Ich würde einen ssh Zugang ohne Passwort ermöglichen. Hier zu gibt es genügend Anleitungen und ich nutze das auch und funktioniert:

                                  https://www.dotkam.com/2009/03/10/run-commands-remotely-via-ssh-with-no-password/

                                  Dann kann man mit einem einfach EXEC Befehl das entfernte System runterfahren ohne irgendwelche Bibliotheken etc.

                                  user@host:~$ ssh remoteuser@remotehost.com sudo poweroff
                                  

                                  Ich habe es gerade nochmal getest - bei mir wurde der Zugriff von iobroker System auf mein GW über meinen FHEM Account:

                                  fhem@MWHome:/home/pi$ ssh pi@192.168..xxx.xxx sudo reboot
                                  bash: warning: setlocale: LC_ALL: cannot change locale (de_DE.UTF-8)
                                  Connection to 192.168..xxx.xxx closed by remote host.
                                  

                                  Reboot funktioniert. 😉

                                  Auch andere Kommandos

                                  fhem@MWHome:/home/pi$ ssh pi@192.168.xxx.xxx uname -a
                                  bash: warning: setlocale: LC_ALL: cannot change locale (de_DE.UTF-8)
                                  Linux MWIPv6GW 5.10.63-v7+ #1459 SMP Wed Oct 6 16:41:10 BST 2021 armv7l GNU/Linux
                                  

                                  MWHome ist das lokale iobroker System
                                  MWIPv6GW ist das remote System

                                  Sprich das Ganze (also ssh Zugriff ohne PW) muss man halt in diesem Fall unter der iobroker Kennung machen - dann funktioniert das auch aus dem Skript. Die ssh Schlüssel müssen also alle im iobroker Home Verzeichnis /home/iobroker/.ssh liegen.

                                  Zusätzlicher Vorteil: In den Skripten sieht man keine Passwörter etc. da man sich ohne PW anmeldet - aber eben nur mit einem bestimmten User und nur von einer bestimmten Maschine und unter bestimmter Userkennung.

                                  Chaot 1 Reply Last reply Reply Quote 0
                                  • Chaot
                                    Chaot @mickym last edited by

                                    @mickym Er muss ja eigentlich nur die Zeile 7 ändern.
                                    Aber deine Methode funktioniert auch recht interessant.

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

                                    Support us

                                    ioBroker
                                    Community Adapters
                                    Donate

                                    398
                                    Online

                                    31.8k
                                    Users

                                    80.0k
                                    Topics

                                    1.3m
                                    Posts

                                    5
                                    16
                                    790
                                    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