?
Solved

find latest files and ftp to another server

Posted on 2012-04-09
6
Medium Priority
?
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
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 38

Expert Comment

by:Gerwin Jansen, EE MVE
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

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

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…
Suggested Courses

752 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