Formatting files for Unix/Linux

sugarcrmdevelopers —  September 10, 2008 — Leave a comment

I was recently working with a customer and they were moving files about their Linux servers. Any time they edited a file, they downloaded it to their Windows desktop and changed it with Notepad. Then they would upload it back to the server using FTP in text mode.

Notepad adds Windows formatted EOL characters (End Of Line). When the file is uploaded back to the Linux box using FTP in text mode, the file now has a bunch of bad characters that affect the way PHP parses the code.

While this can happen at any time after editing files remotely, I ran into this most often when moving Sugar installations from server to server and we needed to edit the config.php or config_override.php files.  We first saw this issue when the Web Services API started failing mysteriously (see below):

EOL chars from Windows on a Unix-style server

The easiest thing is to use an editor like vi or emacs on the Linux server.  But if you don’t have SSH access, then be sure to upload files using FTP in binary mode. I also recommend Notepad++ for Windows. On a side note, I haven’t run into this issue on Mac OS X.

However, if all else fails, you can use this command to recursively change all text files from DOS format to UNIX format:

for i in $(find . -name "*" -exec file {} ; | grep text | sed 's/:.*//g'); do dos2unix $i;done;

That command is safe to run against any instance of Sugar. It will not attempt to convert the file unless it is a text file. dos2unix must be installed on your server and you’ll need shell access.

No Comments

Be the first to start the conversation!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s