Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SFTP Scripting and Log capture

2998055Jan 28 2016 — edited Jan 29 2016

Hi All,

Need help in below query, appreciate your help.

We are changing a FTP process to SFTP ( passwordless SSH )

I had few queries on how to log the transfer details into a log file.

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

PUTLOGFILE= /xxx/ftp_log.log

FAILPUTLOGFILE= /xxx/fail_ftp_log.log

In FTP we use

ftp -v -i -n $FTPHOST > $PUTLOGFILE 2> $FAILPUTLOGFILE <<END_SCRIPT

What does the above command do in FTP wher put in a script ?

If I change it to SFTP can i use the below to transfer file to remote server and capture details in log file

sftp -v -i -n user1@10.10.10.10 > $PUTLOGFILE 2> $FAILPUTLOGFILE <<END_SCRIPT

Please advice.

Basically , I want to

connect from server1 to server2 for SFTP

Copy files for server1 to server2

If successfull copy -- archive files form source server1 directory to archive directory

In copy fails -- exit

I want to do it through SFTP (SSH connections through public key has already established)

Below is the code , Kindly advice if there are any mistakes.

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

#!/bin/sh

. $CUST_TOP/admin/setftpconninfo.env

OUTFILEDIR="/opt/oracle/applprd2/apps/apps_st/appl/cust/outbound"

ARCHIVEDIR="/opt/oracle/applprd2/apps/apps_st/appl/cust/outbound/archive"

REMOTETODIR="/test/inbound"

PUTLOGFILE="/opt/oracle/applprd2/apps/apps_st/appl/cust/intf_monitor/log/ftp_put.log" #log when successful

FAILPUTLOGFILE="/opt/oracle/applprd2/apps/apps_st/appl/cust/intf_monitor/log/ftp_put_fail.log" #log when fail

DATE=`date '+%y-%m-%d'`

echo "SFTP - OutBound Files"

cat /dev/null > /opt/oracle/applprd2/apps/apps_st/appl/cust/intf_monitor/log/ftp_put.log

cat /dev/null > /opt/oracle/applprd2/apps/apps_st/appl/cust/intf_monitor/log/ftp_put_fail.log

cd $OUTFILEDIR

#To Transfer prod update Files

shopt -s nullglob

for f in prod_update*.csv;

do

echo "Processing $f file.."

sftp -v -i -n user1@10.10.10.10 > $PUTLOGFILE 2> $FAILPUTLOGFILE <<END_SCRIPT

lcd $OUTFILEDIR

cd $REMOTETODIR

#binary

put $f $REMOTETODIR/$f

quit

END_SCRIPT

EXITSTATUS=`wc $FAILPUTLOGFILE | awk '{print $1}'`

if [ "$EXITSTATUS" != "0" ]

then

echo "FTP Connection Failed"

exit -1

else

echo "$f has been Successfully moved to FTP Destination $REMOTETODIR"

mv $OUTFILEDIR/$f $ARCHIVEDIR

rm -f $OUTFILEDIR/$f

fi

done

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

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 26 2016
Added on Jan 28 2016
1 comment
896 views