The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Log file not getting updated KornFire High Level Programming 4 10-21-2008 04:12 AM
Find last updated file callimaco0082 UNIX for Dummies Questions & Answers 4 09-04-2008 11:17 AM
checking out latest updated file asadlone Shell Programming and Scripting 3 05-08-2008 05:16 AM
/etc/utmp file does not get updated with boot up details jyoti_mil UNIX for Advanced & Expert Users 1 06-11-2007 11:41 AM
Creating an updated file dbfree Shell Programming and Scripting 4 09-30-2005 04:23 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-06-2008
cbo0485 cbo0485 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 87
If File has been updated, do something??

Put this together from somewhere else on the forums, just modified it and added the loop.



Code:
#!/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:


Code:
/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:


Code:
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.
  #2 (permalink)  
Old 11-06-2008
sumeet sumeet is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 33
cat file1 > file2

lets say file1 gets updated.

diff file1 file2 > file3.

if [ -s file3 ]
do something. (in your case FTP)
fi

thanks
Sumeet
  #3 (permalink)  
Old 11-06-2008
cbo0485 cbo0485 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 87
Script:


Code:
diff archive.tar backup.tar > tmp
if [ -s tmp ]; then
/tmp/abcQATest/abcMoveTest.sh archive.tar /tmp/archive.tar
echo "Files different, transferring files"
else
echo "Files the same, exiting";
fi

Results:


Code:
/tmp/abcQATest>./autoMoveScript.sh
Binary files archive.tar and backup.tar differ
Files the same, exiting
/tmp/abcQATest>

The binary files do differ, but then for some reason it always goes to the second part of the if statement.

Last edited by cbo0485; 11-06-2008 at 05:17 PM..
  #4 (permalink)  
Old 11-06-2008
BubbaJoe's Avatar
BubbaJoe BubbaJoe is offline
Registered User
  
 

Join Date: Oct 2008
Location: St Louis
Posts: 153
I believe you have to use the -a parameter on the diff command to compare binaries.
  #5 (permalink)  
Old 11-07-2008
cbo0485 cbo0485 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 87
Quote:
Originally Posted by BubbaJoe View Post
I believe you have to use the -a parameter on the diff command to compare binaries.
It worked, but now even if archive.tar and backup.tar are the same, it says their different and it runs the first block, instead of just doing the echo which states "Files the same, exiting";


Code:
diff archive.tar backup.tar > tmp
if [ -a tmp ]; then
/tmp/abcQATest/abcMoveTest.sh archive.tar /tmp/archive.tar
echo "Files different, transferring files"
cat archive.tar > backup.tar
else
echo "Files the same, exiting";
fi

  #6 (permalink)  
Old 11-07-2008
cbo0485 cbo0485 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 87
Here's my final code I got working.



Code:
cmp archive.tar backup.tar > /dev/null
if [[ $? -eq 1 ]]; then
/tmp/abcQATest/abcMoveTest.sh archive.tar /tmp/archive.tar
echo "Files different, transferring files"
cat archive.tar > backup.tar
else
echo "Files the same, exiting";
fi

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0