Need to dynamically create a file

I'm trying to write a script that generates a file of varying size filled with random text and am having some difficulties.

The major problems are that I'm limited to csh and a lot of the systems I have to run this on don't have a /dev/random (so a wrapper around the dd if=/dev/random or dd if=/dev/zero commands won't work).

This script is going to be run on varying UNIX operating systems and, as I've said, the lowest common denominator is csh. I'd like to make this as cross-platform as possible.

Anyone have any recommendations?

Could you provide a bit more information? Such as a use for such a script.

Sure. I'm going to use it to generate a file to ftp to/from multiple systems for network benchmarking.

I already have all the ftp parts automated, I just can't figure out how to generate the file dynamically before ftp kicks in (I don't actually want to keep the files, they just need to be around for the ftp's).

Being limited to csh and not having /dev/random hurts a bit.

Sorry bro, sound's too fishy to me. I don't see a need to create such files dynamically for 'benchmarking'. If I'm wrong then I wish you luck.

cat /bin/* | dd

or something like that.

I'm not sure what you mean by 'fishy' but just because *you* don't see a need for it doesn't mean it isn't legitimate. I really don't want to leave 100-300MB files laying around for when my management gets a wild hair to see how our network connections are doing.

In the future, a simple "I don't know" would suffice instead of calling into question my purpose.

Someone else wish to give me a hand?

No need to get bent out of shape.

Calling into question people's intent usually puts them on the defensive. Had you just said "I don't know" I would have had zero problems.

Next time think before you hit submit.

You seem to be taking this rather personally. Have you been struggling with this issue for a while? Do you think you might benefit from a break for a chance to look at it from a fresh perspective?

What I would benefit from is people helping me solve this problem instead of calling to question my intent, then wondering why I'm being defensive. If you can't understand that, then I have neither the patienct nor the energy to explain it to you.

Either you wish to help me or you don't. If you wish to help, great! Otherwise, move on.

Unfortunately, that didn't generate a file large enough, but it does give me some other ideas.

Thanks Perderabo.

Here is the idea i have ....

1)create a junk file having varying lines of lengths of data ....

2)put a while loop for number of files u want ...
if u want 100 files repeat the loop 100 time

get the random number using the following

3)x=`expr $RANDOM % 1000`

4) Using this random number 'x' get the xth line from junk file
put it in the randomfile using date upto seconds
since time changes for evry sec ... u will have 60 diff files in a minute.

 d=\`date \+%T\`

5) echo "xth line" > $d.dat

6).use sleep if u want ....

Hope this is not junk idea !! :slight_smile: :slight_smile:

He is using csh so no RANDOM variable is maintained by the shell.

Firstly, I don't use csh (I use bourne variants), so your milage may well vary. Also; I don't know whether the lack of /dev/(u)random will effect the ability of awk to generate random numbers?

awk -vu=$upper 'BEGIN {
srand();
printf( "%0.0f\n", rand() * u );
}'

There are lots of other ideas in a script over at shelldorado although all but one seem to depend on either some kind of device file (random or urandom), or a RANDOM shell builtin.

Some kind of date manipulation may be your only option.

Cheers
ZB

I want to write a shell script that will create files/folders. Can any one suggest.