I need to be able to copy a text file to another location and then delete the contents of this text file (without deleting the file).
At the moment I am doing this:
#!/bin/bash
count=0
for filename in `find . -name "*_list" -print`
do
while read -r line
do
echo $line
sync
echo "### Trace Info ###" > log.txt
sync
python worker.py "$line"
echo $line > traces/trace$count.txt
sync
sync
sleep 1
sync
sync
cp log.txt traces/trace$count.txt
#cp log.txt traces/log.txt
sync
sleep 1
count=$((count+1))
done < $filename
done
But calling sync and sleep it not working for me, instead I get file like this:
(NOTE: the python file is not writing to log.txt CacheGrind is.)
CachegrindMemMod/vg-in-place --tool=cachegrind --trace-children=yes /usr/sbin/mysqld 2>log.txt
cat trace10.txt | xxd
0000000: 2323 2320 5472 6163 6520 496e 666f 2023 ### Trace Info #
0000010: 2323 0a00 0000 0000 0000 0000 0000 0000 ##..............
0000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
This trace has 4 megs of zeros which should have been text.
ls -la trace10.txt
-rw-r--r-- 1 root root 4350121 2012-04-29 15:34 trace10.txt
I am guessing there is some caching going on that is preventing me from being able to get the accrual text. Any ideas would be great.
If you are interested the file should contain a list of memory addresses retrieved from a modified version of CacheGrind that looks like this:
Dw: 0x4916e30
Dw: 0x4916df0
Dw: 0x4916db0
Dw: 0x4916d70
Dr: 0x4916d30
Dr: 0x4916cf0
Dr: 0x4916cb0
Dr: 0x4916c70
Dr: 0x4916c30
Dr: 0x4916bf0
Dr: 0x4916bb0
Dr: 0x4916b70
Dr: 0x4916b30
Dr: 0x4916af0
Dr: 0x4916ab0
Also modified version of CacheGrind can be found here
Additional Info:
I noticed some file only contain the header and no null data. This also leads me to think its an I/O caching problem
Who’s writing in that log.txt file? The python script? Is it working in the background? If so, why are trying to copy the (not completed) file? Why are you trying to sync in the bash script?