SFTP Scripting and Log capture


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SFTP Scripting and Log capture
# 1  
Old 01-27-2016
SFTP Scripting and Log capture

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.
Code:
-----------------------------------------------------

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.
Code:
-----------------------------------------------------------------------------------------

#!/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

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Not able to capture sftp error in Korn Shell

I am not able to capture error condition in sftp in Korn Shell #!/bin/ksh sftp batch@uat >abc 2>&1 << ENDFILE cd public put /data/WELCOME_55 ENDFILE ret_val=$? if ] then print file "copied successfully" else print file "NOT copied successfully" fi return 0 Now the... (9 Replies)
Discussion started by: Soham
9 Replies

2. Shell Programming and Scripting

Sftp in shell Scripting issue

I have the below code for ftping a file sftp "ogl@serverna,me"ogl@serverna,me <<EOF cd $path_on_the_server binary put $path_on_my_sever/filename.txt bye EOF Not sure is this works.but when i tried its asking for password .How i can avoid asking password and provide it in the... (5 Replies)
Discussion started by: shyamrad
5 Replies

3. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

4. Shell Programming and Scripting

Log Capture for Background Process

Hi , I am running a backgorund process called hello.sh ./hello & Now i need to capture the log file as it produces the output . i am not able to use " >> " nor " tee " to capture the output file / log file . Please let me know how can i do it ? Regards, Deepak Konnur (3 Replies)
Discussion started by: dskonnur
3 Replies

5. Shell Programming and Scripting

capture last run log using dsjob

Hi All, Could you please let me know how to capture the WARNING or FATAL errors for the last run log using dsjob -logsum in Korn Unix Shell. Thanks in Advance, (0 Replies)
Discussion started by: HemaV
0 Replies

6. Shell Programming and Scripting

How to capture return value from java in shell scripting

Hi All, My shell script will call a java component with some arguments , the java component returns a string value to the shell script. How to assign the return value to the shell variable. Here is the sample code. In my shell script i am calling the java as fallows. --exporting... (1 Reply)
Discussion started by: rajeshorpu
1 Replies

7. Shell Programming and Scripting

Sftp scripting

Dear All, I have script that get the files from sFtp server to Unix server. The script is below. -- Batch File (mybatch) cd Output get abc123.csv in/abc123.csv get def456.csv in/def456.csv get ghi789.csv in/ghi789.csv bye -- Script File sftp -b mybatch xyz@111.222.33.4 >... (1 Reply)
Discussion started by: samrio
1 Replies

8. Shell Programming and Scripting

SFTP scripting - help required

Hi all, First post so go easy guys....... I've seen this asked before on some other forums but never properly/fully answered. My problem involves the automation of an SFTP script sending from F-Secure (ssh2) HP-UX, to Windows FTP server (ssh2) running VShell. We've set up SSH keys but while... (8 Replies)
Discussion started by: b0bbins
8 Replies

9. Shell Programming and Scripting

capture nohup log file

Hi, I am running my script using nohup, but I am not able to capture the log file for that process could naybody please help... Here is what I am doing.... nohup ./script & 1>/home/user1/log.txt but I am not able to capture the log.....Is there anyother way I can capture the log... (2 Replies)
Discussion started by: mgirinath
2 Replies

10. Shell Programming and Scripting

sftp scripting

I am totally new to this forum so if I am asking this and it has already been asked I apologize, but I have yet to have time to figure out how to search effectively for answers in previous posts. I'll figure it out tomorrow I just wanted to get this out there in case there is someone with this... (6 Replies)
Discussion started by: New_Guru
6 Replies
Login or Register to Ask a Question