[NTLUG:Discuss] shell script help needed
David
d4588 at rocketmail.com
Thu Apr 26 13:40:18 CDT 2001
Hey guys,
I have been tasked to create a script to get files from
a remote ftp server 209.x.x.x and send them to an ftp server in
Wichita,KS. which is on our 10.x.x.x network.
The script I have now works as long as I run it
manually.But when I run this script from the cron
it never gets the first directory listing from the
first server.
---begin script---
#!/bin/sh
##########################
# varibles
#
##########################
d_remote="209.x.x.x"
w_remote="10.x.x.x"
# list files to retrieve
files="ION2*"
# local directories
local="/home/delliott/ftp"
# remote directories
d_offsite="/remote/"
w_offsite="/remote/"
# remote username and password variables
d_user="username"
d_pass="passwd"
w_user="username"
w_pass="passwd"
domain="ACG\\"
# variables used in log file
n=`diff 209.file 10.file | awk 'FS=" " {print $2}'`
date=`date`
#########################
# take a snapshot of remote files
# and put a listing of them in files
#########################
echo "dir" | ftp ftp://$d_user:$d_pass@$d_remote$d_offsite \
| grep ION2 | awk 'FS=" " {print $9}' > $local/209.file
echo "dir" | ftp ftp://$domain$w_user:$w_pass@$w_remote$w_offsite \
| grep ION2 | awk 'FS=" " {print $9}' > $local/10.file
#########################
# do comparision to see what files need to be grabbed
# from the remote site
#########################
cd $local
# compare the local list to the remote list,strip off the leading
#'<' and then
# put into a file called needed
diff 209.file 10.file | awk 'FS=" " {print $2}' > needed
#########################
# start transferring missing files to the remote
# ftp server in 10.file.
#########################
for i in `cat needed`;
do echo "get $i" | ftp ftp://$d_user:$d_pass@$d_remote$d_offsite;
done
for i in `cat needed`;
do echo "put $i" | ftp ftp://$domain$w_user:$w_pass@$w_remote$w_offsite;
done
echo "Transferred" $n, on $date >> /var/log/transfer.log
# script to remove the 10.file,209.file and needed files.
./clean.sh
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
More information about the Discuss
mailing list