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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ftp and telnet in the same script ?? Urgent Help !!
# 1  
Old 04-26-2006
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.
# 2  
Old 04-26-2006
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
# 3  
Old 04-26-2006
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
# 4  
Old 04-26-2006
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:
Code:
#!/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}"


Last edited by vgersh99; 04-27-2006 at 03:48 PM..
# 5  
Old 04-27-2006
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.
# 6  
Old 04-27-2006
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.:
Code:
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

# 7  
Old 04-28-2006
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/s...uidelines.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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. Shell Programming and Scripting

Urgent Telnet Script

hi all, I want to telnet to a port. aand then run a command called 'show threads' once i'm connected to the telnet prompt. then the respond of this 'show threads' i want to store it in a file on a local system. can someone please help me out here? this needs to be scripted, shell script. ... (1 Reply)
Discussion started by: SkySmart
1 Replies

3. Shell Programming and Scripting

urgent help needed in telnet issue

Hi, Whenever i am trying to telnet to server i am getting frequent error Authorized Login: prtsrc's Password: /dev/pts/171: Password read timed out -- possible noise on port when i am rerunning the same it is working fine thanks, sam (2 Replies)
Discussion started by: sam99
2 Replies

4. UNIX for Advanced & Expert Users

Script should flow after ftp --Urgent

Hi everyone, The script actually does the ftp and gets the file to the local system. I want to do some manipulations for that file , But after doing ftp , script is not proceding and just a prompt is displayed . .... ftp code here...... .................... ............... echo "FTP... (4 Replies)
Discussion started by: kaaakrishna
4 Replies

5. UNIX for Advanced & Expert Users

FTP script urgent

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

6. Filesystems, Disks and Memory

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

7. UNIX Desktop Questions & Answers

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

8. UNIX for Dummies Questions & Answers

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

9. Linux

ftp telnet enable

hi , i have jsut installed linux 9.0 , but i can not ftp or telnet to the system . i have installed the ftp and the telnet server during installation . i have also configured the files to enable the ftp and telnet , the ftp and the telnet daemons are running , but when i do ftp : ftp... (1 Reply)
Discussion started by: ppass
1 Replies

10. IP Networking

FTP or Telnet

Dumb question I'm sure but how on earth do I transfer files from a sco unix machine to my windows 2000 machine. I'm typing commands on my Win2000 machine. All I can seem to do is move files around on the unix system? (8 Replies)
Discussion started by: Timbash
8 Replies
Login or Register to Ask a Question