java telnet app

I need to write a java app that will telnet to a unix server run some commands and grab the output of that command.
can some one give info or point me to some links about sun's telnet class ?

Thanks
nramesh30Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gadioCommented:
There are free implementations of telnet that you can use. Here is one of them:
http://www.first.gmd.de/persons/leo/java/Telnet
0
gadioCommented:
Opps! This was not meant to be a 'proposed answer'. You can reject it if its not an answer for you.
:-)
0
nramesh30Author Commented:
How and where would I specify the user name , password and the command to run ?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

nramesh30Author Commented:
okay . sorry . i got it . its in the wrapper class
0
nramesh30Author Commented:
I'm unable to javac compile telnetwrapper.java file . it gives me lot of class telnetio not found error.
I'am very new to java
0
gadioCommented:
What errors do you get? Please paste it I'll tell you what the problems are.
0
nramesh30Author Commented:
I'am able to compile now. But my app will not know the prompt ahead of time . So I tried to use send() mixed with wait() calls . but it does not work . This is what I tried.
telnet.wait("login:");
   telnet.send("joe" + "\r");
   telnet.wait("Password");
   telnet.send("joeopass" + "\r");

Now what should be my next call ? what do i wait for ?
0
gadioCommented:
Here is a sequance I used and its working for me:


  public static void main(String args[])
  {
    try {
      tio.connect("one.machine.ip.address.com");
      wait("login:");
      send("gadio\r");
      wait("Password:");
      send("my_real_password\r");
      wait(">");  //my prompt
      send("touch /tmp/THIS_WAS_AN_APPLET\r");
      wait(">"); //my prompt
      tio.disconnect();
    } catch(IOException e) { e.printStackTrace(); }
  }
}


Hope this helps you!
0
nramesh30Author Commented:
    wait(">"); //my prompt

Here's where I have the problem. U know ur prompt ahead of time (>). I cannot make that generalization. The code has to be able to handle any prompt.
Because users of the app might have different prompts in their environment.


     
0
gadioCommented:
Not a big problem I think. You can set the prompt as you wish as the first operation of the telnet.
Are these users going to have the same shell (sh / csh / tcsh)? If not - the problem is slightly more complicated...
In any case you will need to have a "smart connection"  that finds which enviroment the telnet is connected to, and then configure whatever is necesarry.
0
gadioCommented:
More problems??
0
nramesh30Author Commented:
Thanks . it works fine.
0
gadioCommented:
So I will answer.
This time - don't ACCEPT the answer...
:-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jscapeCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.