views:

314

answers:

2
<?xml version="1.0" ?>
<project name="test" default="root">
    <target name="telnet">
        <telnet server="10.1.1.1">
            <read>login:</read>
            <write>root</write>
            <read>password:</read>
            <write>${PASSWORD}</write>
            <read>#</read>
            <write>ls</write>
            <read>#</read>
        </telnet>
    </target>
</project>

That is the code I have in a build.xml file. When I run ant (version 1.8, in bash) (I have downloaded and copied over the jars for commons-net-2.0 and jakarta-oro-2.0.8 already), this is the output I get:

Buildfile: /home/sagar/build.xml

telnet:

and then it just sits there. When I do a "who" on my server, I can see "System" waiting on login. But there is no progress after this. I can telnet into the server using normal telnet means (putty, bash, etc).

I even tried the full telnet command instead of read/write:

<telnet server="10.1.1.1" userid="root" password="root">

Any help is much appreciated!

Note: JRE 1.5, Ant 1.8, commons-net version 2.0, jakarta version 2.0.8

A: 

Not an expert in ant (I use Nant on the Dark Side) but looking at the telnet task it looks like there is an attribute called initialCR which sends a carriage return after login - the default value appears to be 'no'.

My thinking is that the username/password has not been submitted, i.e. its just waiting for the "pseudo enter key" to be pressed.

http://ant.apache.org/manual/OptionalTasks/telnet.html

Hope this helps

DilbertDave
Just tried that. No joy. It still hangs, except now it hangs one line lower :SThanks though!
Sagar
+2  A: 

Figured it out. For anyone else who has this issue:

Ant 1.8.0 does not seem to work with commons-net-telnet. Not sure why, but if you can go down to version 1.7, it will work.

6 hours of head banging and frustration later, it is an undocumented version issue. Great! >:

Sagar
Glad you got it sorted and thanks for posting back with the solution - that's what it's all about.
DilbertDave
1.8.1 will work too.
Eduard Wirch
Thanks! I'll try it out.
Sagar