Operating System - HP-UX
1751765 Members
4724 Online
108781 Solutions
New Discussion юеВ

windows and unix file format using Samba 2.0.9

 

windows and unix file format using Samba 2.0.9

Under windows, the text file look dos format correctly, but when I look the file under unix, it is having extra ^M character like unix format.

Why this ^M is showing in my file and how to stop it without running dos2ux command.

Is there any parameter required in smb.conf under global parameters.

I am using Samba(CIFS) 2.0.9 and HP-unix 11.0

Thanks in advance.

Madhav

13 REPLIES 13
Rodney Hills
Honored Contributor

Re: windows and unix file format using Samba 2.0.9

The simple answer is no.

The complex answer is possibly. Samba has an option for each share called "magic script". This script is call on each file as it is closed (it runs on the host side).

Theoritically you might be able to generate a script that ran dos2ux automatically.

The documentation on "magic script" says it is experimental.

Good Luck

-- Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: windows and unix file format using Samba 2.0.9

In answer to why ^M show up.

Unix text files have ^J as line terminator.

Dos text files have ^M^J as line terminator.

The ^M is just another character to unix.

-- Rod Hills
There be dragons...
Wodisch_1
Honored Contributor

Re: windows and unix file format using Samba 2.0.9

Hi Madhav,

what you experience is an application problem, not an operating system problem.
If you need to process the same files (shared via SAMBA, e.g.) from both platforms, you will have to
- convert to and fro all the time
- use compatible(=interoperatible) applications on both platforms
The first would include the use of "dos2ux" and such, the second the use of applications like StarOffice or OpenOffice, which are available on both platforms, and are able to read and store their "data" files (i.e. XML, today) transparently.

Just my $0.02,
Wodisch
Darren Prior
Honored Contributor

Re: windows and unix file format using Samba 2.0.9

Hi Madhav,

To add to Rodney's answer I don't believe you can achieve your aim with magic scripts - they only work for a nominated script for each share.

So, a user would need to open and close the magic script file whenever they made a change to a file from their PC. The magic script would then have to determine which file had been modified (using the file's datestamp) and run dos2ux on it.

The end result of this is that the files would then not be formatted correctly if another user tried to open it from a PC, which could cause confusion.

regards,

Darren.
Calm down. It's only ones and zeros...

Re: windows and unix file format using Samba 2.0.9

In the previous versions of samba, users did not get ^M problem and other unix application used to read the file and work with out any error. Now application is rejecting and giving error due to ^M at the of the line of this data text file. This problem has started after upgrade to Samba 2.0.9.

I can use dos2ux command, but everytime, user has to depend on me before running the other Unix application. User is not happy with this.

Any thoughts above this?

Regards

Madhav

Rodney Hills
Honored Contributor

Re: windows and unix file format using Samba 2.0.9

For all the versions of samba I have used, the ^M issue has been around. Their have been forums discussing this issue and how to address it.

It usually boils down to since samba is doing block writes (not examining "records"), then it would cause more problems to automatically strip out the ^M. For instance a binary file like .zip should not be touched.

The only tool I know that strips the ^M during a network copy, is "ftp". Even in that situation, you tell ftp that the file being copied is ascii.

Any unix application we write, we add ^M if we know a PC app will be reading it, and when we read a file we know is from a PC, then we have the application strip it out.

What version of samba were you using before the upgrade? It doesn't make sense that any earlier version would behave differently.

-- Rod Hills

There be dragons...
Shannon Petry
Honored Contributor

Re: windows and unix file format using Samba 2.0.9

First, I find the ^J pretty funny. That is not why it happens at all. Understanding the problem may help you understand why you have it and can not solve it easily.

Unix uses a Carriage Return for a new line. Simple and Easy.
DOS uses a Carriage Return AND a Line feed. Since Any windows is still DOS this is how it saves files.

When you have a share between the two systems and users in Unix and Windows creating text files, your Unix users will see ^M(linefeed) on the end of each line of text made in DOS.

The Kicker here is that even though the Geniouses at MS made text files to have 2 character new lines, if they encounter a UNIX made file with simply a carriage return, they will automatically add the line feed to it to make it a DOS text file.

Samba is not capable of fixing this problem, nor is CIFS or any other file/print sharing software for that matter, and it has never been the case with Samba. I have been using Samba for 3 1/2 years and never seen it automagically know who is opening the file and translate new line's accordingly.

The simple answer is scenario based.
1. If all your users need the text files in windows, write your own cron job to run every file through unix2dos.
2. If you have users in both arena's that need the text files write your own cron job and run all files through dos2unix.
Scenario 2 will work, because like I said Notepad, Wordpad, and Word automatically add the DOS required linefeed character to plain text files. Unix is WYSIWYG.

Regards,
Shannon
Microsoft. When do you want a virus today?
Rodney Hills
Honored Contributor

Re: windows and unix file format using Samba 2.0.9

Shannon,

Unix text files have ^J (hex 0a), as displayed by the "xd" command, as the end of line character.

You press the CR key at the keyboard, but unix writes the text line with a ^J in the file.

Try it-
xd somefile | more

You will find all text lines terminated with 0A.

-- Rod Hills
There be dragons...
harry d brown jr
Honored Contributor

Re: windows and unix file format using Samba 2.0.9

If the user isn't happy with it, then tell the user to quit using M$ products :-)

6 Feb 2000 - 9 Feb 2000 (21 posts) Archive Link: Using NT registry calls to solve CR-LF issue with text files.

Any old Unix hand will know all about line endings. MS-DOS text files are supposed to end their lines with the two ASCII characters CR and LF, whereas Unix text files usually just end lines with LF. Mac OS, like the earliest Apple II DOS before it, simply uses CR. Any user of a system that supports file access to/from multiple platforms will run into this incompatibility sooner or later; usually, text files must be converted manually from one format to another, since it is difficult for a computer to divine what is or isn't a "text file", as opposed to a binary file which must not be tampered with. Periodically, the issue comes up on the Samba lists of how to convert text files to and from the MS-DOS line-ending standard. One standard answer: on Windows, just use WORDPAD instead of NOTEPAD, since WORDPAD can work with Unix-style text files. Another common answer: use a preexec script to convert all the files in a share whenever a client mounts the share.

http://kt.linuxcare.com/samba/sm20000217_12.epl


live free or die
harry
Live Free or Die