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
Code:
tail -f binfile
but I need the bytes in hex format. Therefore I use hexdump
Code:
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
Code:
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
Code:
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 ?
Last edited by maloe; 09-10-2009 at 04:39 PM..
Reason: tail [COLOR="Red"][B]- f[/B][/COLOR]
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 ...
Hello *nix specialists,
Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Hi All,
Iam new to unix scripting and I want a split a string into 4 characters each, leaving the last two characters and convert the splitted values into binary.
For example:
string='ffd80012ffe20000ffebfffeffea0007fff0ffd70014fff1fff0fff0fff201'
this should split as
ffd8
0012
ffe2
.
.... (5 Replies)
Hi
I need to display the binary text of an clearn text which is sent as input to the shell script (c shell);
ex: I will pass "HELLO" as input, and i should get the binary format of the text
Thanks in advance
Mohan (1 Reply)
Folks,
can anyone help with a script to convert hex to binary digits, and break the 32 bit binary into packs of 4 and send them to 8 different variables.Any help is sincerely appreciated.
Thanks
venu
Its in korn shell...... (24 Replies)
i hav tried to convert binary 2D data into text using binreader and writing into text file using streamwriter.
i use ReadSingle() function to convert from binary to ascii, although it works good in 1D data but not in more dimensions.
the kind of values i get are
-1.265369923E+038
and like
... (2 Replies)
Hi all,
I have a print control file (dflt) for Oracle which is in binary. As I am going to develope an application in Window environment, I would like to reference the dflt file. But it is in binary format and I cannot access it. Anyone can suggest me how to convert the file into text or... (5 Replies)
Dear Experts
I need to read a binary file. I know for example in byte number 3801-3804 there is a 4 byte number embeded. Is there a way to extract this number from this file and then convert it to ascii via unix??
Your help would be highly appreciated.
Very Best Regards
Reza (5 Replies)
Here is what I did . . . . I FTP'd several *.pdf files from a web site to a UNIX server, and did not set the transfer mode to BIN, now Adobe thinks that the documents are corrupted. Is there a way to convert the *.pdf files to Binary so that Adobe can open them again. I would just re-download... (2 Replies)