Everytime when a specific binaryfile grows (in 4 byte steps) I want to get the newest 2 bytes immediately when they occur. That can be done by
tail -f binfile
but I need the bytes in hex format. Therefore I use hexdump
tail -f binfile | hexdump -x
what only prints out complete lines of 16 bytes. But I need the last bytes immediately when the binfile grows not waiting until 16 bytes are reached. So I tried
tail -c 2 binfile | hexdump -x
where hexdump prints the last 2 bytes only but tail stops after that and does not check the binfile constantly.
I put this into a loop, checking the binfile for changes in filesize
while [ ]
do
newsize=$(ls -l $binfile | awk '{print ($5)}')
if [ $newsize != $oldsize ]
then
hexchar=$(tail -c 2 $binfile | hexdump -x)
fi
done
So, in principle this works but I think this is no good style and performance optimized, is it? Any ideas how to convert the byte directly out of tail -f binfile ?
Output is line by line. If every 2 seconds 4 new bytes "xxxx xxxx" are appended to the binary file, then every new output line is printed after 8 seconds.
But what I need is the "xxxx xxxx" immediately. So it should be somthing like
Now there is no output at all. It's not as simple as reformating the the last line. The problem is, that hexdump collects all bytes until a comlete row of 16 byte is printed. When I use hexdump -n4 then it outputs the last 4 bytes, but tail -f stops running
Thanks for your answer. Unfortunately there is no perl on that machine and I cannot test it. But perhabs I can find out how to make an executable file ...