ftp and telnet in the same script ?? Urgent Help !!

Hi All,

I have written a script which ftp certain file to other machine and as the ftp completes , I want to connect to that machine ( at which the file is ftped) .

Now the problem is that my script ftp's the file but it does not telnet to that machine. Suppose I am at machine1 and I want to ftp and then telnet to machine2 I am writing my script as:

ftp machine2 << END_SCRIPT
-- some cmds--
--
--
quit

telnet machine2
--some cmds-
--
--
END_SCRIPT

My script is only ftping and not telnetting.... I don't know why. I have even tested this that It is not telnetting.

Plz help ASAP.

Aru.

seems like you're trying to telnet WITHIN the here-doc for the FTP - cannot do that.
Have your FTP complete [the here-doc block] - then telnet

Now I am able to telnet to machine2 with certain changes.

But when it connect to machine2... it gives me following error and cmds are not executed as it get connected to machine2.

Changes made are:

ftp machine2 << END_SCRIPT
-- some cmds--
--
--
quit
END_SCRIPT

telnet machine2 <<END_SCRIPT
--some cmds-
--
--
END_SCRIPT

Error is (when it try to connect to machine2 through telnet) :

Trying IP_OF_MACHINE2...
Connected to machine2
Escape character is '^]'.
Connection closed by foreign host.

I am providing the user name and psw for the machines through variables.
Plz let me know if any body has some idea about this.

Thnx..
Aru

you cannot use the here-doc paradigm for telnet as you're for ftp.
you'll have to either switch to 'expect' or use a 'poor man' inline telnet like so:

#!/bin/ksh

host='myHOST'
user='myUser'
passwd='myPasswd'

    (
    sleep 3
    print "${user}"
    sleep 1
    print "${passwd}"
    sleep 2
    print "ls ~"
    sleep 1
    print "exit"
    sleep 3
    ) | telnet "${host}"

Hi vgersh99... thanks for all your replies.... Now what I am doing is that for telnet here-doc I am using
telnet machin2 << END_SCRIPT1
...
...
...
END_SCRIPT1

It let me connect to machine2 but It is asking me again for login and psw. But i am providing it at the begining of the script through variable....

I am pasting my actual script ( with some info changed) plz correct me if you see sth wrong in that.

I am ftping abc.tar from machine1 to machine2 and then trying to connect to machine2 to untar that file (abc.tar) at machine2.

The script is as follows:

USER=xxxxx
PASSWD=xxxxxx

cd /app/siebel/siebel7/siebsrvr
cd bin
echo Now at: `hostname`
pwd
echo =========================NOW FTPING========================================
ftp -n gpsappxxx.corporate.com<< END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd /app/siebel/swse/public/test
echo Now at: `hostname`
pwd
bin
put abc.tar
sleep 1
bye
END_SCRIPT
sleep 2

echo ============================NOW TELNETING===================================
telnet gpsappxxx.corporatecom
<< END_SCRIPT1
quote USER $USER
quote PASS $PASSWD
cd /app/siebel/swse/public/test
sleep 1
echo `tar -xvf abc.tar`
sleep 1
echo `rm abc.tar`
ls -ld
exit
END_SCRIPT1
echo Again at: `hostname`
pwd

I need an urgent help..... If possible plz modify the script if it is required.

Aru.

As I said in the previous posting - 'you cannot use the here-doc paradigm for telnet as you're for ftp'.

You can try something like this, but it's not very elegant - it's a 'poor-man' approach.:

USER=xxxxx
PASSWD=xxxxxx

cd /app/siebel/siebel7/siebsrvr
cd bin
(
   sleep 1
   echo "$USER"
   sleep 1
   echo "$PASSWD"
   sleep 1
   cd /app/siebel/swse/public/test
   sleep 1
   echo `tar -xvf abc.tar`
   sleep 1
   echo `rm abc.tar`
   ls -ld
) | telnet gpsappxxx.corporatecom

Hi vgersh99,

This is what happening when I try run the script as you suggested for the telnet part:

$ ./telnet.sh
Trying 3.32.xxx.xxx...
Connected to gpsappxxx.corporate.com.
Escape character is '^]'.

SunOS 5.8

This computer system may be accessed and used only by company employees
and other authorized personnel and only for legitimate business purposes
and in accordance with applicable company policies and guidelines

[http://webp01.corporate.com/GENews/stories/Infoguidelines.htm].

The Company reserves the right to monitor access and use of Company
systems without any future warning, consistent with applicable law.

By accessing this computer system, you are consenting to monitoring by
the Company to ensure appropriate use and for other purposes. Unauthorized
access or inappropriate use may result in criminal penalties and/or
disciplinary action, up to and including termination.
login: xxxxxxxxxx
Password:xxxxxxxx
Last login: Fri Apr 28 10:26:53 from gpsapp***.corpo
Sun Microsystems Inc. SunOS 5.8 Generic Patch February 2004
$ ./telnet.sh: /app/siebel/swse/public/test: does not exist
Connection closed by foreign host.

----------------------------------

It is making conection with gpsappxx.corporate.com but not navigating to path /app/siebel/swse/public/test

But test directory exist in /app/siebel/swse/public .

Here is my telnet script:

USER=xxxxxxxx
PASSWD=xxxxxxxxx

cd /app/siebel/siebel7/siebsrvr
cd bin
(
sleep 1
echo "$USER"
sleep 1
echo "$PASSWD"
sleep 1
cd /app/siebel/swse/public/test
sleep 1
tar -xvf abc.tar
sleep 1
rm abc.tar
ls -ld
) | telnet gpsappxxx.corporate.ge.com

What can be done now dear ?. Is there any other way also to telnet from one machine to another using script ?

Thanks for your help
Aru

I can see that as it connect to gpsappxxx.corporate.com

it again do ./telnet.sh out there..... which outputs :

$ ./telnet.sh: /app/siebel/swse/public/test: does not exist

It is not doing 'tar -xvf abc.tar' and then 'rm abc.tar'

What can be the issue... why isn't it executing those cmds.

Strange.... is there exist any problem with again.

Aru

make sure that whatever directory you're trying to navigate to using the script DOES exist and has the proper permissions.

try to do the same things manually from the command line that you're doing within the script.

Try this:

(
sleep 1
echo "$USER"
sleep 1
echo "$PASSWD"
sleep 1
print cd /app/siebel/swse/public/test
sleep 1
print tar -xvf abc.tar
sleep 1
print rm abc.tar
print ls -ld
) | telnet gpsappxxx.corporate.ge.com

Cheers..

it wonders me that, even after modification... it is not letting me to go inside telnet loop.

(
...
...
...
) | telnet gpsappXXX.corporate....

It is not connecting to gpsappXXX.

Can some bdy suggest me different telnet script?.

Also I have checked the existing path to be correct. I am able to connect to gpsappXX from machine 1 when I go through each and every command manually....... but, not thriugh script????. Where is the problem?.

I have to get some telnet script..... plz help. May be your suggestion helps me . Plz suggest any other sol if possible.

Thnx..
Aru

Any specific errors..
I am able to do on my servers what you are tryin to do...