Problem with logging into remote host

Hi All,

   I am using a script for remotely logging into a rhost using telnet and shutdown a server. The script is as follows.

IP = 10.24.12.23; export IP
UNAME = username ; export UNAME
PWD = password; export PWD
CRDIR = /etc/rc.d/init.d ; export CRDIR

echo "logging into remote host"

(
telnet $IP << EOF
$UNAME # username for logging into rhost
$PWD # password for logging

cd $CRDIR
sh shutdown.sh stop # for shutdowning the server
$PWD # password for shutdowning the server

logout
EOF ) >> log.$$

When I execute this script, I am getting an error saying that "unknown host". Can you please let me know what the problem is? If you know any other way of logging into a remote host. Can you please let me know ASAP.

THanks in Advance,
Patil.

It seems to be a problem with blanks, try:

IP=10.24.12.23; export IP
UNAME=username ; export UNAME
PWD=password; export PWD
CRDIR=/etc/rc.d/init.d ; export CRDIR

Hi,

Thanks for the reply, but in the script whatever I have written has not blank spaces. It is returning an error

"Closed by a foreign host"

Please let me know if anyone has faced this error and what was the solution.

Thanks in advance,
Patil.

You cant use redirected input with telnet ... you need to use a tool like expect: http://expect.nist.gov/

Try something like this:


IP=10.24.12.23
UNAME=username
PWD=password
(
    sleep 2 
    echo "$UNAME"; sleep 2
    echo "$PWD"; sleep 2
    echo "pwd; whoami; hostname; exit"   # Commands here.
    sleep 2
) | telnet "$IP"

Regards.