Solved

deleting files with bad characters from mounted Windows drives

Posted on 2004-04-15
7
947 Views
Last Modified: 2013-12-26
I have a script that mounts to a Windows drive, and is supposed to delete an entire subdirectory from the Windows drive.  I have rights to the files on the drive.  Here is my script:

#!/bin/sh

cd /root/tcm
rm -f beijingtcm.tar.gz
rm -rf BeijingTCM
mkdir BeijingTCM

# Unmount and remove remote directories
cd /
umount mnt/beijingtcm
cd /root
rm -rf /mnt/beijingtcm

# Make remote directory
mkdir /mnt/beijingtcm

# Mount to Windows shared drive
mount -t smbfs -o username=xxxxxxx,password=xxxxxxx,workgroup=AD //ausnt-018.ad.cirrus.com/tcm /mnt/beijingtcm

#rm -rf /mnt/beijingtcm/BeijingTCM/
mv /mnt/beijingtcm/BeijingTCM/* /root/tcm/BeijingTCM/
rm -rf /mnt/beijingtcm/BeijingTCM/
mkdir /mnt/beijingtcm/BeijingTCM/

cd /root/tcm
sh ./getfile

cd /mnt/beijingtcm/BeijingTCM/
tar -xvzf BeijingTCM.tar.gz
rm -f BeijingTCM.tar.gz

cd /root/tcm
rm -rf BeijingTCM

The problem I'm having is when it gets to the mv /mnt/beijingtcm/BeijingTCM/* statement.  It tries to move the subdirectories and their files to a temporary directory on my Linux server for deletion later, but it has trouble trying to move or delete some of the files, because they have weird characters in the filename.  Some of the errors include the following:

mv: reading `/mnt/beijingtcm/BeijingTCM/Orion/\250\215\253Y\372\253E\253 \346\253 Orion.lnk': Invalid or incomplete multibyte or wide character

mv: reading `/mnt/beijingtcm/BeijingTCM/Sonata1_Playability/Resources/058 CDDA-DTS Retailed A\217\346A\024\226E\220.lck': Invalid or incomplete multibyte or wide character

Is there a way to force the script to either move or delete these kinds of files without giving this error?  If I can't move or delete them, I can't create the new directory for the incoming archive.  Thanks!
0
Comment
Question by:texasreddog
7 Comments
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 10834885
Try to loop on list of files, and for each one put " " around the filename
0
 

Author Comment

by:texasreddog
ID: 10835048
so will something like this work?

mv "/mnt/beijingtcm/BeijingTCM/*" /root/tcm/BeijingTCM/

or if I just want to delete without moving, can I do this?

rm -rf "/mnt/beijingtcm/BeijingTCM/"
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 10835459
I don't think the GNU mv command cares much about multibyte character filenames.  I ran strings on my /bin/mv, and I couldn't find the error message mv is reporting.  That leads me to think the error message is coming from the kernel, or a kernel filesystem driver.  It could be that your destination filesystem is picky about disallowing filenames that don't meet its expectations for multibyte characters.

Also, the mv command is fast when moving files round inside a mount, but not very useful for moving files from one mount to another.  In the cross-mount case, "mv /device1/a /device2/b" is basically equivalent to running the two commands "cp /device1/a /device2/b ; rm /device1/a ".  Since you're running a rm -rf on the directory anyway, you could just use a cp command.  Using a cp -R will let you avoid the wildcard expansion too in case your shell is somehow creating the problem.

"cp -R /mnt/beijingtcm/BeijingTCM/ /root/tcm/BeijingTCM"
 can replace
"mv /mnt/beijingtcm/BeijingTCM/* /root/tcm/BeijingTCM/"

I haven't run this, so you might have a BeijingTCM/BeijingTCM directory in there.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:texasreddog
ID: 10836029
I tried the cp -R command, and it copies the files, but it still won't let me delete the directory, which is what I really need to do.  This error in my first post appears to be a headache for other Linux users:

http://www.redhat.com/archives/fedora-list/2004-January/msg00973.html

If anyone can find a good solution to this, please let me know.
Thanks!
0
 
LVL 22

Assisted Solution

by:NovaDenizen
NovaDenizen earned 50 total points
ID: 10836360
Read this comment from that thread:
http://www.redhat.com/archives/fedora-list/2004-January/msg00915.html

He fsck'ed the filesystem, and it turned out to have errors.  After fsck fixed them, the problems went away.

Since you're remote-mounting via samba, you might try running "chkdsk" on the windows machine in question.

0
 
LVL 12

Accepted Solution

by:
stefan73 earned 50 total points
ID: 10840388
Hi texasreddog,
It looks like Linux has problems handling "truncated" (real or imagined) multi-byte file (Unicode) names on your Windows drive. Check your Samba documentation on how to disable character translation.

In worst case, you need to correct those file names on the Windows side.

Cheers,
Stefan
0
 

Author Comment

by:texasreddog
ID: 10843172
I agree.  That's the conclusion I came up with.  The files on the Windows side should be renamed to handle better in Linux.  And a chkdsk wouldn't hurt, either.  I'm going to split the points and close the question.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 56
Process filename extension 3 156
centeredAverage challenge 8 120
changeXy challenge 13 56
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now