Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

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
Avatar of amit_rj27
amit_rj27

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

Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answers