Operating System - HP-UX
1830898 Members
2985 Online
110017 Solutions
New Discussion

Re: FTP to multiple systems from a script

 
SOLVED
Go to solution
fg_1
Trusted Contributor

FTP to multiple systems from a script

Hello all

I am trying to figure out how i would be able to accomplish an FTP to 2 or more systems from within the same script, each time I do it, it will only go to the 1st system and then when it hits the next system it tells me that the user is already logged in and fails.

Any clues?


#! /usr/bin/ksh -v

# Environmental section

DATE=`date +%m/%d/%Y`
SCRIPT_SYSTEM=$(uname -n)
DEST06=mmdcux06.chsli.org
DEST10=mmdcux10.chsli.org
USER=fgrosb01
PW=poolgod1
REMOTECD=/tmp
LOCALCD=/home/fgrosb01/syslogproject/messagesfiles
OUTPUT_FILE=/home/fgrosb01/syslogproject/messages_systems
MAIL=/usr/bin/mailx
ADDRESS=frank.grosberger@chsli.org
#! /usr/bin/ksh -v

# Environmental section

DATE=`date +%m/%d/%Y`
SCRIPT_SYSTEM=$(uname -n)
DEST06=mmdcux06.chsli.org
DEST10=mmdcux10.chsli.org
USER=fgrosb01
PW=
REMOTECD=/tmp
LOCALCD=/home/fgrosb01/syslogproject/messagesfiles
OUTPUT_FILE=/home/fgrosb01/syslogproject/messages_systems
MAIL=/usr/bin/mailx
ADDRESS=frank.grosberger@chsli.org

# This section will perform a series of FTP's to each system then taking
# the file located on each system and bringing it back to the local
# collection station system.

ftp -n -v ${DEST06} << EOF
user ${USER} ${PW}
binary
lcd ${LOCALCD}
cd ${REMOTECD}
get messages.mmdcux06
chmod 600 messages.mmdcux06

sleep 30

ftp -n -v ${DEST10} << EOF
user ${USER} ${PW}
binary
lcd ${LOCALCD}
cd ${REMOTECD}
get messages.mmdcux10
chmod 600 messages.mmdcux10

quit
sleep 30

# This section takes each of the files that have been FTP'd from each
# system and will concatenate them into one file for single viewing

cat /dev/null > ${OUTPUT_FILE}
cd /home/fgrosb01/syslogproject/messagesfiles
for i in `ls`
do
echo "****************************************************" >>${OUTPUT_FILE}
echo Contents of $i >> ${OUTPUT_FILE}
cat $i >>${OUTPUT_FILE}
echo "End of report" >> ${OUTPUT_FILE}
echo "****************************************************" >>${OUTPUT_FILE}
done
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: FTP to multiple systems from a script

You are missing an ftp 'quit' command in your first system.
If it ain't broke, I can fix that.
Darren Prior
Honored Contributor

Re: FTP to multiple systems from a script

also the here document needs to be closed off with the EOF at the start of the line after the quit statement.

regards,

Darren.
Calm down. It's only ones and zeros...
Ted Ellis_2
Honored Contributor

Re: FTP to multiple systems from a script

script is missing something for ftp to switch over to the other server:

after your first file transfer completes, go ahead and get rid of the sleep 30 and replace with:

disconnect # this will drop the ftp link to server1
open ${DEST10} # this will open ftp to new server

now delete your second ftp command.. you don't need this and this is what is complaining... it means you already have an ftp session active.

now you should be in business assuming the rest of the script is clean... I built a small script with your syntax using these changes and it worked.

Ted
fg_1
Trusted Contributor

Re: FTP to multiple systems from a script

Ok guys

I made the changes that each of you specified.
Now what is happening is that the script will
run thru both FTP's successfully but the script
will terminate at the end of the 2nd FTP
without hitting the section that takes the
files and combines them.

I tried putting combinations of CLOSE, quit,
or DISCONNECTS to end the FTP with no
success.

Any ideas?

#! /usr/bin/ksh -v

# Environmental section

DATE=`date +%m/%d/%Y`
SCRIPT_SYSTEM=$(uname -n)
DEST06=mmdcux06.chsli.org
DEST10=mmdcux10.chsli.org
USER=fgrosb01
PW=poolgod1
REMOTECD=/tmp
LOCALCD=/home/fgrosb01/syslogproject/messagesfiles
OUTPUT_FILE=/home/fgrosb01/syslogproject/messages_systems
MAIL=/usr/bin/mailx
ADDRESS=frank.grosberger@chsli.org

# This section will perform a series of FTP's to each system then taking
# the file located on each system and bringing it back to the local
# collection station system.

ftp -n -v ${DEST06}<< EOF
user ${USER} ${PW}
binary
lcd ${LOCALCD}
cd ${REMOTECD}
get messages.mmdcux06
chmod 600 messages.mmdcux06
disconnect

open ${DEST10}
user ${USER} ${PW}
binary
lcd ${LOCALCD}
cd ${REMOTECD}
get messages.mmdcux10
chmod 600 messages.mmdcux10
disconnect
close ${DEST10}

# This section takes each of the files that have been FTP'd from each
# system and will concatenate them into one file for single viewing

cat /dev/null > ${OUTPUT_FILE}
cd /home/fgrosb01/syslogproject/messagesfiles
for i in `ls`
do
echo "****************************************************" >>${OUTPUT_FILE}
echo Contents of $i >> ${OUTPUT_FILE}
cat $i >>${OUTPUT_FILE}
echo "End of report" >> ${OUTPUT_FILE}
echo "****************************************************" >>${OUTPUT_FILE}
done



Evert Ladrak
Advisor

Re: FTP to multiple systems from a script

You'll have to put a EOF after the close ${DEST10}. Otherwise the commands in the script are still passed onto ftp which will not understand them. In short it should something like.

ftp -n -v << EOF
...
...
close ${DEST10}
EOF

# This section takes each of the files that have been FTP'd from each
# system and will concatenate them into one file for single viewing

....
....

Evert
Balaji N
Honored Contributor

Re: FTP to multiple systems from a script

Hi,

The EOF should be there before the cat command.

Modify your script as below.

ftp -n -v ${DEST06}<< EOF
...
close ${DEST10}

EOF
cat /dev/null > ${OUTPUT_FILE}
...

Hope this helps.
-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.