PDA

View Full Version : Applescript - Bizarre issue with vhost file in SL apache




kannary
May 30, 2011, 03:08 AM
I have a bizarre issue: I have an applescript (actually inside automator, but all the same) that creates an entry in the vhost file for apache to add a virtual server. The script works fine and adds the entry, which is properly formatted and closed:

<VirtualHost *:80>
DocumentRoot /Users/Klima/Sites/testsite
ServerName testsite
ServerAlias *.testsite
</VirtualHost>

Here is the weird part: When I restart the server, it gives me a syntax error and fails to restart. It keeps telling me the <virtualhost> is not closed, but it is. The vhost file looks fine and complete (I have been doing this for years). The ODD this is that if I edit ANYTHING on the file and resave it, it works fine, and by ANYTHING I mean ANYTHING....delete an empty space, retype any character....in another words, it won't work unless I edit it manually and resave it. No weird hidden characters, no estrange file encoding (Western MacOS Roman with Unix LF), no missing tags....the file as changed by applescript looks pristine, but it simply will not work. And it is weird because the manual edit can be anywhere in the file, even on prior entries not added by applescript. I can even just delete a character or empty space, retype it leaving the file identical as before I edited it, save it and it works.

The applescript is authorized to write with permissions and throws no errors. Works fine. I even tested removing the "*" and adding the 127.0.0.1 instead....no dice.

Bizarre.

Anyone has any ideas what this could be? I am at a lost. An yes, I guess I could manually edit the vhost file and resave, but....it sort of defeats the purpose of having an applescript generate the file for me.



jiminaus
May 30, 2011, 07:19 AM
It seems clear the editor is changing something. Line endings and encoding are the only things that come to mind. As I don't see any non-ASCII characters, that seems to rule out encoding, leaving line endings.

If you hexdump -C vhost and look at the new lines before and after editing do you notice any changes?

kannary
May 30, 2011, 07:27 AM
Thanks a lot for the reply. Yeap, it is a weird one.

Sorry, I just edited this as I did not read the post well. I will try it.

chown33
May 30, 2011, 12:25 PM
You say the file is identical, but things can appear identical when they really aren't.

The obvious test is to do a low-level compare before and after.

The 'cmp' command compares byte by byte. Try that. Post any differences.

Or use the 'hexdump -C' command before and after, then diff the hex output. Again, post any differences.