Solved

find latest files and ftp to another server

Posted on 2012-04-09
6
314 Views
Last Modified: 2012-04-10
I have a script that will ftp all archive log files from one machine to another but need to find just the files that have not been copied over and just ftp them.

I am on AIX 5.3

Here is the script I am using...

#!/bin/ksh
set -xv
################################################################ script to ftp archive logs.
###############################################################
export ORACLE_BASE=/app/oracle/product
export ORACLE_ADMIN=/app/oracle/product/admin
export ORACLE_HOME=/app/oracle/product/db10.2
export LD_LIBRARY_PATH=/app/oracle/product/db10.2/lib
#
###############################################################
#
cd /oradata/prod/logarch1
echo  `date +%m%d%y-%H:%M` > /home/oracle/arch/ftp_arch.log
for next_file in  $(find /oradata/prod/logarch1 -name 'prod_arc*.log'  -print   )
do
ftp -ivn servername>> /home/oracle/arch/ftp_arch.log  <<eof
user username password
binary
cd /oradata/prod/logarch1
put $(basename ${next_file})
bye
eof
done
echo  `date +%m%d%y-%H:%M` >> /home/oracle/arch/ftp_arch.log
0
Comment
Question by:bkreynolds48
  • 3
  • 3
6 Comments
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 37824802
hi, do you need to use FTP or are other programs an option as well? i'm thinking of rsync instead
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 37824906
Given the rules where I work can't use rsync
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 37824935
In that case, I'd be doing this in a few steps:

- get remote file list using FTP
- get local file list
- diff remote and local file list (call this to_ftp)
- put files that are in the to_ftp list to remote location

It will require some scripting though...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:bkreynolds48
ID: 37824941
so how do I script this?
0
 
LVL 37

Accepted Solution

by:
Gerwin Jansen earned 500 total points
ID: 37826961
I don't have time to write you a complete script but this is basic idea:
FTPHOST=servername
FTPSRCDIR=/oradata/prod/logarch1
FTPDSTDIR=/oradata/prod/logarch1
FTPLIST_LOC=local_archive_files
FTPLIST_REM=remote_archive_files
FTPLIST_DIFF=files_to_ftp
FTPTMP=temporary_ftp_script

# get local list, output to file
ls ${FTPSRCDIR}/prod_arc*.log > ${FTPLIST_LOC}

# ftp to get remote list, output to file
ftp ${FTPHOST} <<EOFTP > /dev/null
ls ${FTPDSTDIR} > ${FTPLIST_REM}
quit
EOFTP

# diff list_prev and list, output to diff_list
diff ${FTPLIST_LOC} ${FTPLIST_REM} | grep "^>"  | awk -- '{print $10}' > ${FTPLIST_DIFF}

# create FTP script to get files
echo "ftp ${FTPHOST} <<EOFTP > /dev/null" > ${FTPTMP}
echo "bin" >> ${FTPTMP}
echo "cd ${FTPDSTDIR}" >> ${FTPTMP}
echo "lcd ${FTPSRCDIR}" >> ${FTPTMP}
for cur_fil in `cat ${FTPLIST_DIFF}`
do
	echo "get \"${cur_fil}\"" >> ${FTPTMP}
done
echo "bye" >> ${FTPTMP}
echo "EOFTP" >> ${FTPTMP}

# calling FTP script
echo sh ${FTPTMP}

Open in new window

You can use this to build your script, note the echo on the last line: scripts is not executed unless you remove the echo - test on a test server first in any case :)

Note that the script assumes that you have the FTP details in a .netrc file (not secure btw).
0
 
LVL 1

Author Closing Comment

by:bkreynolds48
ID: 37827916
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Move nodes from one TSM to another. 3 61
Skill Development 15 163
check unix curl command return value 7 86
How to check the PVU´s on AIX TSM servers? 3 76
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now