Put this together from somewhere else on the forums, just modified it and added the loop.
#!/bin/ksh
localFile=$1
remoteFile=$2
#source FTP parameters
. .ftp_put.cfg
mylog=ftp_session.log
echo "$(date "+%H:%M:%S") - Attempt to FTP $1 to $2" > $mylog
machine="server1 server2 server3 server4"
count=0
# do the FTP put
for machine in $machine
do
ftp -i -n <<EOF >> $mylog
open $machine
user $FTP_LOGIN $FTP_PASSWORD
put $localFile $remoteFile
ls $remoteFile
quit
EOF
count=`expr $count + 1`
done
This script gets called by another script through a cron job every 5 minutes:
/tmp/abcQATest/abcMoveTest.sh archive.tar /tmp/archive.tar
Anyways, I was wondering if there was any way of making it a little better. Currently this simply ftp's that static file every 5 minutes, regardless of if the file has been updated or not. The way it works now is if someone needs to make an update to the 4 server's that this script FTP's to, they simply drop their archive file(named archive.tar) to the /tmp/abcQATest/ directory, and then within 5 minutes the crontab runs and ftp's their file to server 1-4 at the /tmp/archive.tar location.
Is there any way to set this up so it only ftp's the file if it's been updated since the last time the ftp ran? That way, if it gets updated, it get's FTP'd once, but then it doesn't get FTP'd again unless the file's been changed?
Then on the other 4 servers, I also need something like this:
If /tmp/archive.tar has been updated
do something
.
.
else
endif
The do something part is just a couple quick moves, extracts and deletes, that's no big deal. It's If statement I am stumped on.