Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

temporary filename generation for ftp

 
SOLVED
Go to solution
Michael Schulte zur Sur
Honored Contributor

temporary filename generation for ftp

Hi all,

I am looking for a script that generates a filename max 8chars long with a selectable letter first and the rest made of a value computed from ip and time and user so that I can put a file without risking that another machine does tha same thing.

thanks for any ideas,

Michael
3 REPLIES 3
Highlighted
John Palmer
Honored Contributor

Re: temporary filename generation for ftp

Hi Michael,

Have you considered using ftp's store unique facility instead? This guarantees that your file won't overwrite any other.

Regards,
John
Simon Hargrave
Honored Contributor
Solution

Re: temporary filename generation for ftp

Michael

If you can stretch to 9 characters, you could do something like this: -

echo "obase=16;$(( date ; uname -a ; id ) | cksum | cut -d" " -f1)" | bc

Basically runs date, uname, id and whatever else you might like to use, through cksum to generate a checksum. Then passes this through bc to convert to hexadecimal, and so restrict to a max 8 chars.

If you need it to be 8 chars including your "prefix", you could perhaps just cut the first or last 7 chars from this number?
Michael Schulte zur Sur
Honored Contributor

Re: temporary filename generation for ftp

Simon,
your idea is simple and ingenious. I think I will go on from there.

John,
your idea isn't bad either. Can I be sure that sunique is supported on all major platforms?

thanks both,

Michael