Solved

find latest files and ftp to another server

Posted on 2012-04-09
6
324 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
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!

 
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 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

724 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