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

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



hiya gerald,

On Thu, Jan 02, 2003 at 05:11:02AM -0600, Gerald Livingston wrote:
> 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.

instead of using date +%s, incrementing, and sleep, how about 
using date +%s%N?  what you can do is something like

while [ ! $doneyet ]; do
	FN="`date +%s%N`.jpg"
	[ ! -f $FN ] && doneyet=1;
done

this way:

- there's less chance of collision with nanoseconds
- if there is a collision, it simply tries again immediately (and will
  get a new value from %N)
- no need to sleep or do shell arithmetic

> 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.

i think better than suppressing the output would be to test if the
file exists before doing something to it with [ -f $filename ]

> 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.

cool.  to be security paranoid though, is this ftp connection going across
a non-secure connection?

> 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?

yeah, try "basename file"


hth
	sean

Attachment: pgpv9cXN4PX7V.pgp
Description: PGP signature


Reply to: