Weird error reading files
Weird error reading files
- Subject: Weird error reading files
- From: Andrew Oliver <email@hidden>
- Date: Mon, 22 Aug 2005 17:29:11 -0700
I have a script acting as an IM gateway, sending me various status messages
from systems on my network.
Servers on the network write messages to a shared file on an NFS server. The
AIM script periodically checks the file and relays any contents to me via
AIM.
The messaging part isn't the problem, but I've run into a problem with
reading the file (via 'read file') that I just can't explain.
A server on the network might log a message such as:
16:56:12 <b>Server name</b> something important happened here<br>
Most of the time this would be read by the script, relayed and the file
cleared.
Sometimes, though, the script incorrectly reads the file, and I can't
understand why. I can understand even less how it reads the file.
When it chokes, all that is relayed is the first two characters, reversed.
So, in the above example, I might get a message '61' as being the first two
characters '1' and '6' from "16:56:12".
I've spent some time debugging this.
I've verified the correct message is getting written to file.
There doesn't appear to be a timing/file lock contention issue (the message
maybe logged 20 or 30 seconds before the script tries to read it and
chokes).
I've added a check to see if the read contents are two characters and if so,
try reading the file again - the second read *always* has the right content.
So my questions:
1) Why doesn't the script read the entire file contents? (are there any
known problems with 'read file'?)
2) Why are the first two characters being reversed? (I can't even begin to
explain that one)
3) Is there a better solution than the double-read hack?
Script:
on checkLogfile()
-- read the current log
set msg2Send to read file logFile -- logFile is predefined, and valid
-- skanky hack here
if (number of characters in msg2Send ) = 2 then
set msg2Send to read file logFile -- works the second time!
end if
if msg2Send "" then -- do we have something to say?
-- clean out the file
set f to open for access file logFile with write permission
set eof f to 0
close access f
sendIM( msg2Send )
end if
end checkLogFile
Andrew
:)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden