UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 3rd, 2003, 03:25 PM
gusdcat gusdcat is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 2 gusdcat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unix Script cannot copy filename with brackets

i am trying to write a bash script to backup recent files from a directory.

it works well, except that it does not copy files whose names have brackets.

(i.e. banner[1].jpg)

any advice on how i might be able to do this, or on code that would find and rename such files before i run my copy script?

thanks!

-matt


my script
____
#!/bin/sh

# this script will backup all files from the last month to a secondary location


date=$(date "+%m-%d-%y")
# mkdir backup_$date
cd /Volumes/192.168.1.15/apps/GoldMine/Mailbox/Attach/
find . -mtime 1 | \
while read file

do

#avoiding pesky trivial output
if [ "$file" = "." ]
then
else
echo "$file"
cp "$file" /Volumes/192.168.1.108/ScriptTest/backup_$date/"$file"
fi
done

Reply With Quote
  #2  
Old October 3rd, 2003, 05:47 PM
gusdcat gusdcat is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 2 gusdcat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
solved my own problem using the tr command

# this script will backup all files from the last month to a secondary location



date=$(date "+%m-%d-%y")

mkdir backup_$date

cd /Volumes/192.168.1.15/apps/GoldMine/Mailbox/Attach/

find . -mtime 1 | \
while read file

do
# file2 holds the filename without brackets
echo "$file" > temp.txt
file2=$(tr -d [] < temp.txt)

#remove bracket characters in target so copy operation will not fail
if [ "$file" != "$file2" ]
then cp "$file" /Volumes/192.168.1.108/ScriptTest/backup_$date/"$file2"


#do nothing to the directory you are in
elif [ "$file" = "." ]
then echo backup started on `date`

#copy an entire directory
elif [ -d "$file" ]
then cp -r "$file" /Volumes/192.168.1.108/ScriptTest/backup_$date/"$file"


else

cp "$file" /Volumes/192.168.1.108/ScriptTest/backup_$date/"$file"

fi
done

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Unix Script cannot copy filename with brackets


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway