Solved

find latest files and ftp to another server

Posted on 2012-04-09
6
315 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, 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 37

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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 1

Author Comment

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

Accepted Solution

by:
Gerwin Jansen, EE MVE 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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…

773 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