Compare binary to exported textfiles and find which binary files have changed or are next since last export

StackOverflow https://stackoverflow.com/questions/23664858

Domanda

I have a folder full of binary files of a proprietary format which I have to export to a textfile using a clumsy software, finally I end up with a folder full of file pairs as such:

myfile1.bin
myfile1.bin.txt
myfile2.bin
myfile2.bin.txt
myfile3.bin
myfile3.bin.txt

I get constantly new bin files pushed to the server so that the filesize of myfile3.bin might have changed and I now have a new myfile4.bin. So I need to periodically check which bin files have changed (size / timestamp) from the txt files and which bin files to not have a txt file and write them in a changed.txt file that I can load with the software to convert the new files.

I think I would have to keep a list of files currently in the folder (including timestamp and size) and compare the folder content in 10 minutes with the saved information to see what changed.

Any ideas and help is greatly appreciated!

È stato utile?

Soluzione

Please check if Following helps:

#!/bin/bash 
while [ 1 ] 
do 
        ls -ltr /dir_to/Monitor > out.txt  # you can try ls -1l as well, depending upon the requirement
        sleep 600 
        ls -ltr /dir_to/Monitor  > out1.txt 

        if diff out.txt out1.txt > diff.txt; then 
                echo "Not Changed"
        else 
                echo "Changed" # diff is changed
                cp diff.txt diff_$(date +%s).txt #Copy the diff to a different file. 
        fi 

done 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top