O
O
Odessamarin2013-01-11 15:36:21
macOS
Odessamarin, 2013-01-11 15:36:21

How to make a telnet session through Automator?

Hello, I discovered such a wonderful tool in Mac OS as Automator.
There is a desire to automate the sending of different commands to the router. Tell me how to write scripts using Automator. By hand, it looks like this.
- I start the terminal
- I enter "telnet 192.168.1.1"
- it asks login, I enter admin
- it asks for password, I enter admin
- I enter "show adsl"
- I get a connection ststu.
I want to make everything automatic, I clicked on the app application made in automator, and immediately got the adsl status.
I'm sure this is possible. But, it doesn't work. I tried through Workflow - Run shell Script ...
I can't enter commands sequentially.
If anyone has done this or have ideas, please let me know.
Thank you.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
iStyx, 2013-01-14
@iStyx

You need regular AppleScript:

set statusCommand to "show adsl"
tell application "Terminal"
  do script "telnet 192.168.1.1"
  set wID to id of front window
  delay 1
  do script "admin" in front window
  delay 1
  do script "admin" in front window
  delay 1
  do script statusCommand in front window
  delay 1
  set startLine to 1
  set answer to every paragraph of (contents of window id wID as text)
  do script "exit" in front window
  repeat with lineNumber from 2 to count of answer
    tell item lineNumber of answer
      if it contains statusCommand then
        set startLine to lineNumber
      end if
      if it starts with "Connection closed" then
        exit repeat
      end if
    end tell
  end repeat
  set status to items (startLine + 1) thru (lineNumber - 1) of answer
end tell
set od to AppleScript's text item delimiters
set AppleScript's text item delimiters to ASCII character 13
display dialog status as text buttons {"OK"}
set AppleScript's text item delimiters to od

V
Valentine, 2013-01-11
@vvpoloskin

Too platform dependent. Maybe a better python/perl/php solution?

O
Odessamarin, 2013-01-11
@Odessamarin

I thought through terminal commands or apple script.

P
Pavel Mir, 2014-02-12
@facetheheat

You don't need a regular AppleScript, but a regular terminal.
router.sh:

expect \"$\"
send \"telnet 192.168.1.1\r\"
expect \"login:\"
send \"admin\r\"
expect \"Password:\"
send \"admin\r\"
expect \"#\"
send \"show adsl\r\"
expect \"#\"

Then you can run it through Automator / AppleScript Editor -> application

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question