amit_rj27
asked on
dos2unix across filesystems (SuSE Linux SP2 "dos2unix" version 3.1-317.2)
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
# 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.
--------------------------
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) = ?
--------------------------
# 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
dos2unix <infile >outfile
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.