Solved

find latest files and ftp to another server

Posted on 2012-04-09
6
313 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

708 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

13 Experts available now in Live!

Get 1:1 Help Now