blog SyKoHPaTh

Line Endings

/bin/sh: /usr/local/sbin/.php: /usr/local/bin/php^M: bad interpreter: No such file or directory

I have a php script that is run as a cron job. I get this error when I try to run it from the command line, and this is due to line endings being saved as Windows (CRLF) instead of plain old Unix (LF). A few methods to fix this, however, they weren't quite working - reg ex searches "completed" but didn't change them.

1) vi .php
2) :set fileformat=unix
3) :w

Magic. This forces the file to be saved as Unix, and changes all the line endings to match. :x and test...


No error, so cron job will work fine now!