Unable to automate telnet login

i have to connect windows server from one of the unix box so i am using telnet and below is my following code

 
#!/bin/sh
host=hostname
log=loginid
port=23
pass=password
cmd1=mkdir test1234
( echo open ${host} ${port}
sleep 1
echo ${log}
sleep 3
echo "\r\n"
sleep 3
echo ${pass}
sleep 5
echo "\r\n"
sleep 3
echo ${cmd1}
sleep 1
echo exit ) | telnet

and now when i run this in the unix it is taking user id and the next password is showing empty and finally its displaying like LOGN failue: unknown username or bad password.

i dont have expect installed in my unix box so using this approach to automate.

can anyone please help me.

No, you can't do it like this. You would have to use a tool like expect, but even so, this isn't the best way. Two main alternatives exist:-

  • rsh/resh/remsh/rlogin
  • ssh

The first set uses plain ASCII text over the network to shake hands with a server that will accept your connection. It must be offering the service of course. You would set up a .rhosts file for the user you are connecting to.
The second is better in many ways and should be preferred if your server offers SSH. You can set up a key-pair and authenticate the client connection request and then usage is much easier and the connection is encrypted (data compression built in if you have lots of output)

What client and server OS and versions are you operating. Do you have any of these services available on the server, or is it really just telnet?

It also depends what you are trying to achieve. is it a true interactive login, or running a command on the server?

Regards,
Robin
Liverpool/Blackburn
UK

What do you need to do on the windows box?

If you just want to transfer files could you use samba or smbclient?

How about running a scheduled task (java, vbscript or the like) to perform the operations on the windows box save the result to a file and then get unix to pick it up using smbclient?

@robin:
sorry for the delay in reply as i was out of office.
tried the alternates provided by you...
rsh iand ssh s not working as it need s a third party in windows to interpret. and when iam trying with resh and remsh its says "a remote has refused an attempt to connecting...."

i am trying to achieve the following:
i have a excel sheet which contains Macros in that and that macros need to be triggered from the unix environemnet.as soon as a process completed in unix at the same time i need to trigger the vb script or a batch script which in turn triggers macro.

any suggestions to move futher is appreciated.

By default a PC (or server) will not respond to ssh ftp etc even if you had software installed...
Merely because you may have to look at its internal firewall and to respond, software isnt enough, you need the related services to run... You wont be able to do anything before you have the service running...

can i get the following info?
i know i can achieve this by using expect.
if i install expect module does spawn and send command works or do i need to instal anythng else arpart from this to make spwan and send work?

Can you perform this task manually?

If you can, then you can use expect to automate it. If you cannot, then expect will not get you anything more.

Robin

expect module is not installed in client unix box. so i thought of auotmating it as per my first post. but it is taking as empty charecters for password. infact iam able to login manually and run some batch script in windows but wheni automate it with the script as pe my first post its not working.
but now i just want to make sure if expect module is installed then can we make use of spwan and send commands. or we need to install speratley anything to make those send and spwan command work.

The login process will empty the input buffer before reading the password you type. I suspect it was designed this way to stop people automating login.

Of course, where there is a will to automate, someone usually achieves it, hence why expect was created. Without a tool like expect on the client side, you will not be able to automate a telnet login. An alternate is to set up services to accept rlogin, rsh/resh/remsh or ssh.

Robin

I have automated telnet with a ksh script. Here is the first time I did that...need script for passwd , can't use expect tool - Page 3 | Unix Linux Forums | Infrastructure Monitoring

It's clunky, but it worked.

ya but only thing is Expect is enough ? or we need to install send and spwan explicitly?

send and spawn are part of the expect language and not something that needs to be installed. Think of them like @sum and @avg are to Excel.

Earlier it was asked if you start from the unix client and type telnet pchost can you then manually type in a user and password and get your vbscript/batch command (s) to run? If you can do all this OK now and all you need is something to automate this already-working process then expect is fine.

If you can't do this manually expect will do nothing to help as it's just a tool to automate a manual process.