Welcome to WebmasterWorld Guest from 54.197.171.28

Forum Moderators: bakedjake

Message Too Old, No Replies

Automating tidy with shell script

-bash: ./TidySite.sh: cannot execute binary file?

   
9:05 pm on Oct 18, 2004 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Newbie warning: I've never done any shell scripting! I have spent the last two hours doing my homework on this and I thought this was good code. Please be patient and if I'm all screwed up please let me know.

I have installed tidy [tidy.sourceforge.net] and would like to automate the task of tidying up all the .html files in a particular directory. However, I am getting this error message and am not sure why:


-bash: ./TidySite.sh: cannot execute binary file

Here's my shell script (saved as TidySite.sh, chmod to 0755):


#!/bin/sh
# run tidy on all html files in particular directory
for FILE in `find /Volumes/Local\ Sites/sites/siteDynamic/ -name "*html"`;
do
tidy -config config.txt -asxhtml FILE
done

The line starting with 'tidy' runs correctly when fed the path to an individual file from the site.

10:05 pm on Oct 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you need $FILE in the tidy line

or you can use xargs:

find /Volumes/Local\ Sites/sites/siteDynamic/ -name "*html" -print0 ¦ xargs -0 tidy ...

The -print0 -0 options allow find/xargs to work with spaces in the filenames.

11:45 pm on Oct 18, 2004 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Using xargs gets it working when I run it from the command line. I'm really impressed, a single line of code and 400+ pages are all tidied up. Thanks for that suggestion, drbrain! :D

If I save it as a shell script, I still get the "cannot execute binary file" error. Revised code, same error:


#!/bin/sh
find /Volumes/Local\ Sites/sites/siteDynamic -name "*html" -print0 xargs -0 tidy -config config.txt -asxhtml

Any suggestions?

6:37 pm on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But the exact same line works fine from the command line?

Is tidy in your PATH?

You should be able to add "echo $PATH" above the find ¦ xargs line to see what the command thinks your PATH is. If tidy is not installed in any of those directories, you need to either add the full path name to tidy to the script, or add the path to tidy to your PATH environment variable.

10:30 pm on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Thanks for your help drbrain! I had almost given up.

It's working now, I just realized the error message was that it thought the TidySite.sh file wasn't a text file.

I opened it in another text editor and resaved it and it worked beatifully after that. What's the correct encoding for a shell script? Shouldn't UTF-8 be correct?

10:49 pm on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your script technically was not even supposed to touch files other than the ones that end with html. And your script ends with .sh. Something is wrong.
4:17 pm on Oct 21, 2004 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



<sheepish>

I had saved it UTF-8 with BOM. :(

</sheepish>