LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   unix2dos problems renaming converted file (https://www.linuxquestions.org/questions/linux-software-2/unix2dos-problems-renaming-converted-file-491012/)

smilingdragon 10-09-2006 11:23 PM

unix2dos problems renaming converted file
 
When I run unix2dos from crontab in suse linux it fails to rename the temporary file created for the conversion.

unix2dos -ascii -n /opt/oracle/admin/scripts/logs/test_file1.lst /opt/oracle/admin/scripts/logs/test_file2.lst

The output shows the following:

unix2dos: converting file /opt/oracle/admin/scripts/logs/test_file1.lst to file /opt/oracle/admin/scripts/logs/test_file2.lst in DOS format ...
unix2dos: problems renaming './u2dtmpqRR8kv' to '/opt/oracle/admin/scripts/logs/test_file2.lst'
output file remains in './u2dtmpqRR8kv'
unix2dos: problems converting file /opt/oracle/admin/scripts/logs/test_file1.lst to file /opt/oracle/admin/scripts/logs/test_file2.lst

The temporary file './u2dtmpqRR8kv' ends up in the home directory.

I think this must be a permissions or possibly a env variable problem as this script works on the other suse linux servers.

I have done some testing to try and pinpoint the problem but am getting frustrated now. :scratch:

any ideas please?

unSpawn 10-10-2006 06:16 AM

Check access rights for your user on file /opt/oracle/admin/scripts/logs/test_file2.lst and dir /opt/oracle/admin/scripts/logs? If that's not it, what does `file /opt/oracle/admin/scripts/logs/test_file1.lst` return?

smilingdragon 10-10-2006 03:34 PM

/opt/oracle/admin/scripts/logs/test_file2.lst doesn't exist until the conversion completes. (on the other server it is 600)

/opt/oracle/admin/scripts/logs/test_file1.lst is 644

/opt/oracle/admin/scripts/logs is 755

file test_file1.lst returns : ASCII text, with very long lines

file test_file2.lst on the other server returns : ASCII text, with very long lines, with CRLF line terminators

smilingdragon 10-10-2006 04:42 PM

Still not sure why it won't work from crontab, but I now have it working from Oracle OEM.

Thanks for the help.

Might put this one down to a UFW (Unidentified Flying Wobbly) ;)

smilingdragon 04-14-2008 05:40 PM

solved it
 
It turns out that when you run the script from cron your current directory (PWD) is set to your home directory. Unix2dos creates the temporary file used in the conversion in your home directory then can't find it to rename it. Not sure why it can't find it.

I added a change directory command (cd) and Unix2dos worked. :)

smilingdragon 04-15-2008 06:20 PM

recode
 
I have been searching the forums for information on why unix2dos behaves as it does and can't say that I had much success.

However I did find mention of the utility recode which is a replacement for unix2dos and dos2unix.

I replaced the unix2dos command with the following:

cp -p test1.txt test2.txt
recode lat1..dos test2.txt

The main difference seems to be that you don't specify a source file and a destination file. (Please correct me if I am wrong.) So I make a copy first and modify the copy. Also you need to specify the characterset. lat1 seems to be the characterset for the linux file and dos is the windows one. So to do the dos2unix it would be dos..lat1.

Anyway recode worked very well from cron and I had no problems with it. Now I just need to convert several scripts to use this instead.

:)

jaewoong.kim 12-31-2008 05:35 AM

this seems similar
 
check this out.
https://bugzilla.redhat.com/show_bug.cgi?id=150277

Quote:

Bug List: (This bug is not in your last search results) Show last search results
Bug 150277 - problems renaming tmpfile to outfile
Status: CLOSED RAWHIDE
Product: Fedora
Component: dos2unix (Show Fedora/dos2unix bugs)
Version: 3
Platform: All Linux
Priority: medium Severity: medium
Target Milestone: ---
Assigned To: Tim Waugh
QA Contact: Ben Levenson
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
Show dependency tree

Reported: 2005-03-04 02:22 EDT by Stephen Beahm
Modified: 2007-11-30 17:11 EDT (History)
Fixed In Version: 3.1-24
Release Notes:
Restrict Group Visibility:
Only users in any of the selected groups can view this bug:
(Unchecking all boxes makes this a more public bug.)
Current Groups: (edit)
None Set

Attachments
Patch for this problem (422 bytes, patch)
2005-09-29 08:50 EDT, Wojciech Milek Details | Diff
View All Add an attachment (proposed patch, testcase, etc.)


External Bugs


Description From Stephen Beahm 2005-03-04 02:22:01 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3)
Gecko/20041020 Epiphany/1.4.4

Description of problem:
The problem is in 'dos2unix-3.1-tmppath.patch'. Memory for the null
terminator is not being allocated.

this code:
fname_len = strlen(dir) + strlen("/d2utmpXXXXXX");

should be:
fname_len = strlen(dir) + strlen("/d2utmpXXXXXX") + sizeof(char);

Version-Release number of selected component (if applicable):
dos2unix-3.1-21

How reproducible:
Sometimes

Steps to Reproduce:
1. dos2unix ./source/common/launch.h



Actual Results: dos2unix: converting file ./source/common/launch.h to
UNIX format ...
dos2unix: problems renaming './source/common/d2utmptfS3dJ' to
'./source/common/launch.h'
output file remains in './source/common/d2utmptfS3dJ'

Additional info:


All times are GMT -5. The time now is 08:48 AM.