views:

191

answers:

1

This script is to connect to different servers and copy a file from a loaction defined. It is mandatory to use sftp and not ftp.

#!/usr/bin/ksh -xvf

Detail="jyotibo|snv4915|/tlmusr1/tlm/rt/jyotibo/JyotiBo/        jyotibo|snv4915|/tlmusr1/tlm/rt/jyotibo/JyotiBo/"

password=Unix11!
c_filename=import.log
localpath1=`pwd`
for i in $Detail
        do

                echo $i
                UserName=`echo $i | cut -d'|' -f1`
                echo $UserName
                remotehost=`echo $i | cut -d'|' -f2`
                echo $remotehost
                remote_path=`echo $i | cut -d'|' -f3`
                echo $remote_path
                {
                echo "open $remotehost
                user $UserName $password
                lcd $localpath1
                cd $remote_path
                bi
                prompt
                mget $c_filename
                prompt
                "
                } |ftp -i -n -v 2>&1


        done

I want to do the similar thing using sftp instead of ftp.

A: 

The solution i got is below:

#!/usr/bin/ksh -xvf

Detail="jyotibo|snv4915|/tlmusr1/tlm/rt/jyotibo/JyotiBo/|import.log     jyotibo|snv4915|/tlmusr1/tlm/rt/jyotibo/JyotiBo/|impor
t_1.log"


for i in $Detail
        do
                echo $i
                remote_path=`echo $i | cut -d'|' -f3`
                file_Name=`echo $i | cut -d'|' -f4`
                echo "cd $remote_path" > .jyoti.batch.dat
                echo "get $file_Name" >> .jyoti.batch.dat
                echo "bye" >> .jyoti.batch.dat
                UserName=`echo $i | cut -d'|' -f1`
                echo $UserName
                remotehost=`echo $i | cut -d'|' -f2`
                echo $remotehost
                sftp -b .jyoti.batch.dat $UserName@$remotehost       
         done
rm -f  .jyoti.batch.dat
Kimi