• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Copying file using bat file only when there are changes to the file.

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is in continuation to earlier post about attaching timestamp to copied file.

When timestamp is attached to the file, ebvery minute timestamp changes. Sp every minute same file is copied, new file will be creted with the new timestamp. Whis is just duplication files.

How can I make sure, that if templating.cfg file has been changed then only copy it otherwise not and leave the timestamp as is ?Change the timestamp only if there have been changes to the file.

Thanks
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

Reference

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.

Programatically

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).

Likewise - what can you make with that?
 
jignesh soni
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?

thanks
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic