Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-25-2009
Registered User
 

Join Date: May 2009
Location: Freeport, IL
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 05-25-2009
Technorati Master
 

Join Date: Mar 2005
Location: service call
Posts: 3,055
Thanks: 4
Thanked 7 Times in 7 Posts
Quote:
# rename all files converted to utf-8 with utf8 extension
mmv -m ";*.utf8" "#1#2"
# deal with .htaccess
mmv -m ";.*.utf8" "#1.#2"
did you mean 'mv' instead of 'mmv'
  #3  
Old 05-25-2009
Registered User
 

Join Date: Sep 2006
Posts: 2,604
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 05-26-2009
Registered User
 

Join Date: May 2009
Location: Freeport, IL
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 05-26-2009
Technorati Master
 

Join Date: Mar 2005
Location: service call
Posts: 3,055
Thanks: 4
Thanked 7 Times in 7 Posts
Quote:
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.
mmv?

I have not heard about, is it for multiple-mv's ? Which distribution is it?
  #6  
Old 05-26-2009
Registered User
 

Join Date: May 2009
Location: Freeport, IL
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
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:
While mmv is typically not included as part of base build for Linux distros, it should be included on the installation media. If not, then you will have to use your favorite package manager (yum, yast, apt, smart, etc.) to install it from the web.
Best Regards,
Brandon
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:48 AM.