troubleshooting Question

dos2unix across filesystems (SuSE Linux SP2 "dos2unix" version 3.1-317.2)

Avatar of amit_rj27
amit_rj27 asked on
Linux
2 Comments1 Solution1194 ViewsLast Modified:
I'm trying to use 'dos2unix' to convert a file to unix format like below:
   
# Create /var/tmp/test file with some contents
eagnmnmep000:/var/tmp # echo "hello" > /var/tmp/test
eagnmnmep000:/var/tmp # cat /var/tmp/test
hello


# Change working directory to /tmp which is a different filesystem then /var
 eagnmnmep000:/var/tmp # cd /tmp

# Execute dos2unix on file in different filesystem then working directory
eagnmnmep000:/tmp # dos2unix /var/tmp/test
dos2unix: converting file /var/tmp/test to UNIX format ...
dos2unix: problems renaming './u2dtmpLYLpO5' to '/var/tmp/test' output file remains in ./u2dtmpLYLpO5'
dos2unix: problems converting file /var/tmp/test

 
# Errors above indicate that new file was not created, but it seems like the original is gone also.
eagnmnmep000:/tmp # ls -l /var/tmp/test
/bin/ls: /var/tmp/test: No such file or directory

 Issue occurs when creating a "new" file as well:
# Create /var/tmp/test in /var filesystem
eagnmnmep000:/var/tmp # echo "hello" > /var/tmp/test
eagnmnmep000:/var/tmp # cat /var/tmp/test
hello

 

# Change current working directory to /tmp
eagnmnmep000:/var/tmp # cd /tmp


# Run dos2unix against /var/tmp/test and create new file /var/tmp/test2
eagnmnmep000:/tmp # dos2unix -n /var/tmp/test /var/tmp/test2
dos2unix: converting file /var/tmp/test to file /var/tmp/test2 in UNIX format ...
dos2unix: problems renaming './d2utmpYg4juV' to '/var/tmp/test2'  output file remains in './d2utmpYg4juV'
dos2unix: problems converting file /var/tmp/test to file /var/tmp/test2


From an 'strace' it looks like it is trying to create a hard link to a different file system which I believe is n't possible.

--------------------------------------8<------------------------------------------------------------------------

stat64("./d2utmpYg4juV", 0xbf94ba8c)  = -1 ENOENT (No such file or directory)
rename("./d2utmpYg4juV' , "/var/tmp/test2") = -1 EXDEV (Invalid cross-device link)
write(2, "dos2unix: problems renaming \'./d"..., 67) = 67
write(2, "          output file remains in"..., 50) = 50
write(2, "dos2unix: problems converting fi"..., 71) = 71
exit_group(1)                           = ?

--------------------------------------8<------------------------------------------------------------------------

 

# Error above, /var/tmp/test still exists this time, but /var/tmp/test2 was not created.
eagnmnmep000:/tmp # ls -l /var/tmp/test
-rw-r--r-- 1 root root 6 Mar 12 13:37 /var/tmp/test


eagnmnmep000:/tmp # ls -l /var/tmp/test2
/bin/ls: /var/tmp/test2: No such file or directory

 It's highly likely that I might be doing a mistake, could you guys please afford some precious time of yours  & help me with this?
 
Also, the same command works/executes fine when both the I/P & O/P files are in the same directory/filesystem and also if the command too is executed from the same directory, so I guess that 'dos2unix' is trying to create a hard link across different filesystems rename("./d2utmpYg4juV', "/var/tmp/test2")  and which I believe is working as designed but I'm n't sure.

Any help will be highly appreciated.

Thank You,
Amit
ASKER CERTIFIED SOLUTION
amit_rj27

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros