This time around I'll just point you at a few clues, and see how you go with them.
You will need a way to see if there is a difference between two files. Since this is being run by a script, you dont really care what the output is, so you could tell it to be quiet in it's output.
There are two ways you can use that program. You can see if any output is produced, and use that, or (in my opinion a better way) you could use the standard diagnostic code from diff to determine if there was a change or not - you would probably want to use a bash built in capability of finding the status of the most recently executed foreground pipeline.
So - how about you see what you can come up from that?
You will also need to have some way of determining which is the last backup file you stored so you can compare it with the production version. I think there are at least 2 easy ways you can find this out:
You could store the name of the last backup file you created in a reference file. You can then read from that file to get your last saved filename.
ls has an option to list files sorted by date. You could use this in conjunction with either the head or tail commands to restrict yourself to either the first or the last item returned from ls (depending on your sort order).
Once new file has been created by copying. How to automatically select this new file and previous file to compare using "diff" ? IF there are differences between the two files, how to make sure that file which is created last, stays ? If there are no changes between the latest file and previous file, then the latest file shd not be saved ?
author and jackaroo
I would do it the other way around - determine which file was the previous one copied, compare it to the current live configuration file, and only if they are different make a backup. Take a look at the section I wrote starting with "You will also need to have some way of determining which is the last backup file you stored..." for some ideas on that.
subject: Copying file using bat file only when there are changes to the file.