Announcement

Collapse
No announcement yet.

HS3 Linux: Telnet Client via Script?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    HS3 Linux: Telnet Client via Script?

    My goal is from HS3 RPi3 to run a telnet session to login to my network switch.

    I have installed telnet on the RPi3 and from the CLI accomplish what I want.

    I want to automated it on a schedule with Easytrigger and events to login to the switch, run a command, logout.

    Any help would be appreciated. I am not a programmer.

    Thanks,

    Jim

    #2
    Hi Jim,

    Take a look at plink.

    Cheers
    Al
    HS 4.2.8.0: 2134 Devices 1252 Events
    Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

    Comment


      #3
      Originally posted by sparkman View Post
      Hi Jim,

      Take a look at plink.

      Cheers
      Al
      Not sure what that is or how it would integrate into HomeSeer.

      Thanks,

      Jim

      Comment


        #4
        I found this:

        http://www.codeproject.com/Articles/...Telnet-library

        In the introduction one of the options is "A program that executes scripts (scripted telnet)" which is what I want to do.

        Have no idea how.

        Thanks,

        Jim

        Comment


          #5
          Originally posted by AutomatedJim View Post
          Not sure what that is or how it would integrate into HomeSeer.

          Thanks,

          Jim
          https://en.wikipedia.org/wiki/Plink

          You would run it as an external program from an event in HS. There's a version for the Pi.

          Cheers
          Al
          HS 4.2.8.0: 2134 Devices 1252 Events
          Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

          Comment


            #6
            Telnet is a PITA to script. I couldn't get it to work with the telnet client, but as sparkman suggests, plink (PuTTY) is an option.

            To install plink,
            Code:
            $ sudo apt-get update
            $ sudo apt-get install putty-tools
            This works on my router (running dd-wrt):

            Code:
            $ (sleep 1; echo user; sleep 1; echo password; sleep 1; echo "ls -al"; sleep 1; echo exit) | plink -batch -telnet 192.168.1.1
            where 'user' and 'password' are the router login credentials, "ls -al" is the command to run, and 192.168.1.1 is the router's address. Don't leave off the 'echo exit' or it will hang!

            If this doesn't work for you, I found another working method that uses a python script. Give a holler if you want to take a look at that.

            Comment


              #7
              Originally posted by zwolfpack View Post
              Telnet is a PITA to script. I couldn't get it to work with the telnet client, but as sparkman suggests, plink (PuTTY) is an option.

              To install plink,
              Code:
              $ sudo apt-get update
              $ sudo apt-get install putty-tools
              This works on my router (running dd-wrt):

              Code:
              $ (sleep 1; echo user; sleep 1; echo password; sleep 1; echo "ls  -al"; sleep 1; echo exit) | plink -batch -telnet 192.168.1.1
              where 'user' and 'password' are the router login credentials, "ls -al" is the command to run, and 192.168.1.1 is the router's address. Don't leave off the 'echo exit' or it will hang!

              If this doesn't work for you, I found another working method that uses a python script. Give a holler if you want to take a look at that.
              @ zwolfpack - installed pLink and your command works great running from PI CLI.


              Originally posted by sparkman View Post
              https://en.wikipedia.org/wiki/Plink

              You would run it as an external program from an event in HS. There's a version for the Pi.

              Cheers
              Al
              @ sparkman - So I can't figure out how to set the event. Do I use run a script or run a program and how do I insert the command?

              Thanks for the help,

              Jim

              Comment


                #8
                I'm not running HS on Linux - but I do know my UNIX So I'll volunteer this as a guess.

                Save this shell script to a file on your rpi, call it something like telnet.sh

                Code:
                #!/bin/sh
                # shell script to run a single telnet command
                
                USER=admin
                PASS=abc123
                IPADDR=192.168.1.1
                CMD="$*"
                
                (sleep 1; echo $USER; sleep 1; echo $PASS; sleep 1; echo "$CMD"; sleep 1; echo exit) | plink -batch -telnet $IPADDR
                Make the script executable:
                Code:
                $ chmod +x telnet.sh
                Then create your event, and for action, select "Run another program or process". Select 'Edit', and navigate to select telnet.sh. In the "command parameters" box, put the command you want to run on your router.

                Of course, this will run only one command. For multiple commands, repeat the same action with the different commands. (Perhaps with a short wait in between?) Or edit the script and hardcode the commands in sequence.

                Comment


                  #9
                  Originally posted by zwolfpack View Post
                  I'm not running HS on Linux - but I do know my UNIX So I'll volunteer this as a guess.

                  Save this shell script to a file on your rpi, call it something like telnet.sh

                  Code:
                  #!/bin/sh
                  # shell script to run a single telnet command
                  
                  USER=admin
                  PASS=abc123
                  IPADDR=192.168.1.1
                  CMD="$*"
                  
                  (sleep 1; echo $USER; sleep 1; echo $PASS; sleep 1; echo "$CMD"; sleep 1; echo exit) | plink -batch -telnet $IPADDR
                  Make the script executable:
                  Code:
                  $ chmod +x telnet.sh
                  Then create your event, and for action, select "Run another program or process". Select 'Edit', and navigate to select telnet.sh. In the "command parameters" box, put the command you want to run on your router.

                  Of course, this will run only one command. For multiple commands, repeat the same action with the different commands. (Perhaps with a short wait in between?) Or edit the script and hardcode the commands in sequence.

                  Thanks for the help. At first it would not run, searched about shell scripts and found I had to change:

                  Code:
                  #!/bin/sh
                  to:

                  Code:
                  #!/bin/bash
                  Basically going to use this to schedule enabling/disabling a switchport so that teenager doesn't stay up all night watching TiVo.

                  Comment


                    #10
                    Originally posted by AutomatedJim View Post
                    Basically going to use this to schedule enabling/disabling a switchport so that teenager doesn't stay up all night watching TiVo.
                    LOL, I remember programming my router so video games wouldn't be going 24/7!

                    Comment

                    Working...
                    X