Operating System - HP-UX
1833875 Members
1779 Online
110063 Solutions
New Discussion

Re: Another Scripting Question

 
SOLVED
Go to solution
Peter Day_2
Occasional Advisor

Another Scripting Question

I've put together a way of getting a random file so that I can check the status of our backups.

But is there a simpler way of getting this random file.

Thanks again,
Pete
9 REPLIES 9
Mark Greene_1
Honored Contributor

Re: Another Scripting Question

what is the file name scheme you are using?


mark
the future will be a lot like now, only later
Peter Day_2
Occasional Advisor

Re: Another Scripting Question

Its a bit messy, but the way that I have done it, to ensure that it is a 'random' file.

bdf |Randomly pick a mounted filesystem
ls | Get a file, if is a directory drill down until I do get a file.

The whole script is about 30 lines, but I'm sure there is an easier way of doing it.
Jeroen Peereboom
Honored Contributor

Re: Another Scripting Question

What about:

generate a random number N
do a find -type f
and use awk to print line N.

JP.
Peter Day_2
Occasional Advisor

Re: Another Scripting Question

Jeroen,
I'd though of that, the problem with this is what level do I set the random number too. There are also certain files that I don't want to get back.

Thanks anyway,
Pete
Elmar P. Kolkman
Honored Contributor

Re: Another Scripting Question

What you could do is get random filesystem and then run ncheck -i on it until you get a file that is acceptable to use as test...
Or get a random number and do:
find -type f | sed 'p'

bdf -i will help you find limits for the random number in the latter case.
Every problem has at least one solution. Only some solutions are harder to find.
Mark Greene_1
Honored Contributor

Re: Another Scripting Question

Given the nature of your situation, if what you have is working and doesn't consume a lot of resources to run, I'd stick with it. It may be ugly, but if it works, that's the important part.

mark
the future will be a lot like now, only later
Jeroen Peereboom
Honored Contributor

Re: Another Scripting Question

Peter,

you may generate more than 1 randomnumber, or retry if the number is too high, although this makes it less random.

(You have posed a question on random numbers. Usually a random generator generates a number between 0 and 1 (no access to manpages iright now). You multiply this by the amount of files you have.)

Why do you want certain files excluded?
You are not restoring the files to the original location I assume?

Greetings,

JP.
Elmar P. Kolkman
Honored Contributor
Solution

Re: Another Scripting Question

As for my find solution: the sed command should be 'sed -n "p"'
Every problem has at least one solution. Only some solutions are harder to find.
RAC_1
Honored Contributor

Re: Another Scripting Question

Is environmental variable RANDOM of any user here?
There is no substitute to HARDWORK