Sign in to follow this  
Followers 0
HSBen

Reading line from Unix screen

6 posts in this topic

I have some terrible version'ing software at work, and I need to check in a ton of modules. I have dirty script that has Sleeps in it, and I was wondering how I would go about being able to read the last line in my unix window so it knows what to enter.

Also is there a way I can send these commands to this windows without it being the foreground? It would be nice to be able to let this run during the day and do other work?

Share this post


Link to post
Share on other sites



AutoIt only runs on Windows (maybe a little WINE), so your "Unix window" is Putty, telnet, or some other console application. The text in those windows is usually not available to AutoIt, but you should be able to run a shell script on the *nix box itself to do something like that.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I have used AutoIt in Linux under wine in the past. It actually works quiet well and the things that don't work are generally rather obvious as to why and can be worked around.

When you say "unix window" what exactly are you referring to? $STDOUT should work fine.

Share this post


Link to post
Share on other sites

There MUST be some way. In fact I know how it can be done.

You can interpret pixel data... define where an app's location is.. and then you have your solution. If you map a number system to pixel data you can equate the two with a one to one ratio ('ratio' may not be the correct word). Whatever do you get me?

If you can define where an app will be positioned on the screen, you can interpret numerical data in the form of pixel data, when you equate the two.

I have not written this yet, because it is not my focus, but simply it can be done with Autoit.

There you go, do you want to write it for me?

Please feed back.


I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

AutoIt only runs on Windows (maybe a little WINE), so your "Unix window" is Putty, telnet, or some other console application. The text in those windows is usually not available to AutoIt, but you should be able to run a shell script on the *nix box itself to do something like that.

:)

Ya, sorry should have said I am using Putty.

I guess its more important to me that I can Send() putty commands without it being the active window.

Share this post


Link to post
Share on other sites

If it's just a telnet session to a unix box, you can establish a connection using sockets within autoit, no external client required.

The code below is more a proof of concept than anything. But I've used it in a few tools to automate things on Tandem systems where I work.

No guarantees that it'll work in your environment, but it should get you started.

#include <string.au3>

Global $host, $conn, $tmpData, $input, $dataTest = 1
TCPStartup()

$host = "10.13.248.39"  ;; IP ADDRESS
$conn = TCPConnect($host,23)
If $conn == -1 Then 
    ConsoleWrite("connect fail: " & @error & @CRLF)
    Exit
EndIf

Sleep(500)
TCPSend($conn,"ÿýÿüÿþÿü")  ;; Sends basic telnet interface defaults
Sleep(750)

While $dataTest

    Do
        $tmpData &= _HexToString(TCPRecv($conn,512,1))
        $tmpData = StringSplit($tmpData,"I",1)       ;; Included to obey "clear screen" command character
        $tmpData = $tmpData[$tmpData[0]]

        Sleep(100)
        
    Until StringRight($tmpData,2) == "> " Or StringRight($tmpData,2) == ": " Or StringRight($tmpData,2) == "? "

    
    $input = InputBox("Ugly Telnet", StringRight($tmpData,512), "", "", 800, 600)
    
    If StringLen($input) Then
        $dataTest = TCPSend($conn, $input & @CRLF)
        Sleep(500)
    EndIf

WEnd

TCPShutdown()

MsgBox(0,"Connection lost","Connection to the server has been lost...")

I didn't bother to develop a gui, this is just a test using an input box. I suppose I could pretty it up a little and it would be a basic telnet client.

Also, I hope all the necessary command characters survive the forum posting.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0