Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Script to FTP a modified file

Script to FTP a modified file


I am fairly new to shell scripting. I see a lot of examples out there of how to find if a file has been modified within a certain period of time. What I'm looking for help with is a script that will run and I'm thinking check for the last 24 hours but if not just check at runtime to see if an HTML file has been modified.

Then once it determines if the file has changed (I've read this can be done with either checksum or the md5 or md5sum commands) then it will FTP the file. I already have an example of how to connect to an FTP and transfer a file but again since I'm new to shell scripting I'd like some help with this.

On another forum I found an example of checking for if a file has been modified and printing things out. Since this will run in the background of a website I don't need it to print but I'm going to post the code here:

# MD5FILE-parameter specifies where we want to save our md5print for
# later use.

# The FILE_TO_CHECK-parameter specifies the file we want to monitor
# changes

if [ ! -f $FILE_TO_CHECK ]
echo "ERROR Couldnt locate file to check:$FILE_TO_CHECK"
exit 1

echo "Taking a print on $FILE_TO_CHECK with md5sum"
MD5PRINT=`md5sum $FILE_TO_CHECK | cut -d " " -f2`

if [ -z $MD5PRINT ]
echo "ERROR Recived an empty MD5PRINT thats not valid, aborting"
exit 1
echo "MD5PRINT we got was:$MD5PRINT"

if [ -f $MD5FILE ]
echo "Found an old savefile:$MD5FILE we trying to match prints"

if [ -z $OLDMD5PRINT ]
echo "Got an empty string from the oldfile, aborting"
exit 1

if [ "$OLDMD5PRINT" = "$MD5PRINT" ]
echo "New and old md5print are identical, the file hasnt been changed"
echo "WARNING the old and new md5print doesnt match, the file has been changed"


echo "Saving to new md5print in logfile:$MD5FILE for later checks"

if [ $? = 0 ]
echo "Wrote to file OK"
echo "Writing to file failed...why??"
exit 1

I'm looking to modify this code to fit my needs. Any help would be greatly appreciated.


RE: Script to FTP a modified file

Not knowing the ins and outs of the files contents.

Thinking about it another way.

Would it matter that's it's changed?, Could you just transfer the file anyway.

What bit of the script you posted doesn't fit your needs?


"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close