|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Working script, Would like someone to look at for me
First off I have to say, it is because of this forum and countless Google searches I have this script working at all. So thank you for that. I have created a web based open source project and I am trying to automate some of the tasks when I am releasing a new version. I do most of my development on my Windows box and have a test site running on a local Linux test server. I have created a script and if I can get a few optimization pointers on it I would appreciate it very much. This script does exactly what I want it to and I want to know, is there a better way? Code:
#!/bin/bash
CONVERT_FROM=ISO-8859-1
CONVERT_TO=UTF-8
# move into our working directory
cd /var/www/localhost/htdocs/dist/
# remove execute bit
find . -type f -name "*.*" -exec chmod 664 {} \;
echo "Files have been modified to remove the execute bit"
# if line endings in our file are windows CR change to unix
find . -type f -name "*.*" -exec dos2unix -q -o {} \;
echo "Dos 2 Unix new line conversion has completed"
# delete any previous utf-8 files so we can write new ones
find . -type f \( -iname "*utf8*" \) -exec rm -f {} \;
echo "Old UTF-8 files have been deleted"
# get all files in our current working directory and make sure they are UTF-8 charset
find . -type f \( ! -iname "*.ttf" ! -iname "*.gif" ! -iname "*.jpg" ! -iname "*.jpeg" ! -iname "*.png" \) -exec iconv -f $CONVERT_FROM -t $CONVERT_TO -s -o {}.utf8 {} \;
echo "New UTF-8 files have been created"
# delete unconverted files so we can move the new files back later
find . -type f \( ! -iname "*.utf8" ! -iname "*.ttf" ! -iname "*.gif" ! -iname "*.jpg" ! -iname "*.jpeg" ! -iname "*.png" \) -exec rm {} \;
echo "Removal of original unconverted files is complete"
# rename all files converted to utf-8 with utf8 extension
mmv -m ";*.utf8" "#1#2"
# deal with .htaccess
mmv -m ";.*.utf8" "#1.#2"
echo "Dist Prep has completed"This is the first step in the rest of my automation scheme. After this runs then I will work on some automated diffs and tar functions. Thanks for any advice. Best Regards, Brandon |
| Sponsored Links | ||
|
|
|
#2
|
|||
|
|||
|
Quote:
|
|
#3
|
|||
|
|||
|
don't have to use that many find commands. you can use it just one time, then pipe whatever files it find to while read loop Code:
find . -type f -name "*.*" | while read FILE
do
chmod 664 $FILE
dos2unix $FILE $FILE
case $FILE in
*utf8* )) rm -f $FILE
esac
#continue
done |
|
#4
|
|||
|
|||
|
ghostdog74, thanks for that it worked perfectly after I removed the extra ). That is much more elegant and succinct then what I had. Code:
find . -type f -name "*.*" | while read FILE do chmod 664 $FILE dos2unix $FILE $FILE case $FILE in *utf8* ) rm -f $FILE esac #continue done matrixmadhan, Yes I was referring to mmv not mv. mmv was something I stumbled on while looking to do recursive file renames because I was having issues getting mv, cp or rename to work. Thanks for the quick responses. Best Regards, Brandon |
|
#5
|
|||
|
|||
|
Quote:
I have not heard about, is it for multiple-mv's ? Which distribution is it? |
|
#6
|
|||
|
|||
|
I am running it on Gentoo and just emerged it Code:
emerge mmv According to the link below you can get it from any other repo I have had a hard time finding just a source package for it though. Linux Blog mmv — move multiple files by wildcard patterns Quote:
Brandon |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script not working with SCO | wollop | Shell Programming and Scripting | 4 | 03-20-2009 12:20 PM |
| Script not working..."sort" not working properly.... | Rahulpict | Shell Programming and Scripting | 23 | 03-16-2009 10:13 AM |
| Script not working. | Nishchal_Nagre | Shell Programming and Scripting | 5 | 01-05-2009 03:40 AM |
| why the below script is not working ., | konankir | Shell Programming and Scripting | 14 | 03-27-2008 03:32 PM |
| FTP script not working | rookie250 | Shell Programming and Scripting | 2 | 12-19-2006 01:49 AM |