Working script, Would like someone to look at for me


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Working script, Would like someone to look at for me
# 1  
Old 05-26-2009
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
# 2  
Old 05-26-2009
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-26-2009
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
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
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
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with speeding up my working script to take less time - how to use more CPU usage for a script

Hello experts, we have input files with 700K lines each (one generated for every hour). and we need to convert them as below and move them to another directory once. Sample INPUT:- # cat test1 1559205600000,8474,NormalizedPortInfo,PctDiscards,0.0,Interface,BG-CTA-AX1.test.com,Vl111... (7 Replies)
Discussion started by: prvnrk
7 Replies

2. UNIX for Beginners Questions & Answers

Why is this script not working?

for file in $(find /home/p611568/*.rpt -mtime -2 | grep -v ftplog) do awk '$1 == "XifPages," {PAGE = $5} $1 == "XifEndOfDocuments," {LINE = $5} index($0,"Value") && index($1,"Info") {sevGTI = 1} END {if (sevGTI) printf "%7s%10s%s",PAGE,LINE ... (4 Replies)
Discussion started by: bcarosi
4 Replies

3. Shell Programming and Scripting

Script not working

Hi i have write the one scripts and the scripts is error. The scripts purpose select one directory to check the file is there or not. i will give the two format of file to search the mention the path one file is there to select the file one copy the another location.please check the my script give... (1 Reply)
Discussion started by: rajivgandhi
1 Replies

4. UNIX for Dummies Questions & Answers

My script is not working

Hi All, I am trying to calculate the total_amount based on two key fields. Here is the script. I am new to unix. So please help me to find out the error in this script. I'm getting error like "command not found" and ]; is missing.. PRE_LBNO=0 PRE_DATE=0 TOT_PAY=0 for line in `cat... (4 Replies)
Discussion started by: lathanandhini
4 Replies

5. Shell Programming and Scripting

expect script inside shell script not working.

Shell Scipt: temp.sh su - <$username> expect pass.exp Expect script: pass.exp #!/usr/bin/expect -f # Login ####################### expect "Password: " send "<$password>\r" it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Discussion started by: bhavesh.sapra
2 Replies

6. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

7. Shell Programming and Scripting

Script is not working from cron while working manually

Hello, I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me 1) How could I check my script when it is running from cron like... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

8. Shell Programming and Scripting

HELP !! script not working..

Hi all, I have a piece of code which cork perfect. It copy the no of lines from some files (*.log) into finalLog file. It read the lines after the line have text "ntot". Here it is : #!/bin/bash ... (10 Replies)
Discussion started by: nrjrasaxena
10 Replies

9. Shell Programming and Scripting

Perl script 'system' linking to local shell script not working

Trying to figure out why this works: printpwd.pl #!/usr/bin/perl use CGI::Carp qw( fatalsToBrowser ); print "Content-type: text/html\n\n"; $A = system("pwd"); $A = `pwd`; print "$A\n"; ^^actually that works/breaks if that makes any sense.. i get the working directory twice but when... (5 Replies)
Discussion started by: phpfreak
5 Replies

10. Shell Programming and Scripting

Script not working..."sort" not working properly....

Hello all, I have a file - 12.txt cat 12.txt =============================================== Number of executions = 2 Total execution time (sec.ms) = 0.009883 Number of executions = 8 Total execution time (sec.ms) = 0.001270 Number of... (23 Replies)
Discussion started by: Rahulpict
23 Replies
Login or Register to Ask a Question