[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[OT] Cleaning up the output of a multiple file rename (bash)

OK, I asked about timing my script because I'm renaming multiple files
using "date +%s" as the base for the new name. I was using a "sleep 1"
in the script to keep the filenames unique because it runs through them
much faster than 1 per second. Too slow if I get a LOT of files. So I
dug around and figured out how to add an incrementing integer as the
last part of the filename.

My problem is that if a particular file extension does NOT exist there
is output to the screen indicating this fact. The new filenames are
being sent to a text file and the output goes there too. I would like to
know how to suppress all output when there is no file to rename.

What I am doing is setting up a script so that HTML/FTP "dumb" users on
an auto-related mailing list that I'm on can send photos as attachments
to a specific email address I have set up. The attachments are split out
by procmail/metamail into a temp directory. The script I'm writing will
rename all the attachments, ftp them to a web folder I will set up, then
generate an email back to the list containing the original TEXT body of
the message accompanying the images plus links to the images themselves.

I also need to figure out how to drop the leading directory name from
the filename when I echo it out to the "links" file though I can script
around that too and clean it up with search/replace after it's
generated. Suppose I could delete the *.xxx lines that way too -- but I
should be able to do it cleanly from the start, right?

The script plus the output and what is echoed to my "links" text file
are below, any assistance appreciated.

Forgive the wrapping, all of the for...done commands are actually on a
single line for each.


$username$:cat names

typeset -i a=1
for i in /home/username/metatemp/*.{jpg,JPG}; 
do mmv "$i" /home/username/metatemp/`date +%s`-$a.jpg; 
a=a+1; done

for i in /home/username/metatemp/*.{gif,GIF}; 
do mmv "$i" /home/username/metatemp/`date +%s`-$a.gif; 
a=a+1; done

for i in /home/username/metatemp/*.{bmp,BMP}; 
do mmv "$i" /home/username/metatemp/`date +%s`-$a.bmp; 
a=a+1; done

for i in /home/username/metatemp/*.{jpg,JPG,gif,GIF,bmp,BMP}; 
do echo "http://www.phorce1.com/hvwcimage/$i"; >>
/home/username/metatemp/links; done

$username$:time ./names
/home/username/metatemp/*.JPG ->
/home/username/metatemp/1041504285-6.jpg : no match. Nothing done.
/home/username/metatemp/*.gif ->
/home/username/metatemp/1041504285-1.gif : no match. Nothing done.
/home/username/metatemp/*.GIF ->
/home/username/metatemp/1041504285-2.gif : no match. Nothing done.
/home/username/metatemp/*.bmp ->
/home/username/metatemp/1041504285-1.bmp : no match. Nothing done.
/home/username/metatemp/*.BMP ->
/home/username/metatemp/1041504285-2.bmp : no match. Nothing done.

real	0m0.102s
user	0m0.020s
sys	0m0.040s
$username$:cat links

Configure your Email to send TEXT ONLY -- See the following page:

gvl2 (Gerald)
AirBall the Rolling Basket Case (1969 Standard Beetle)
LifeSaver (1974 Bay Window Bus)

Reply to: