Re: How can I get a random number in a UNIX shell script???

From: Ernst Lippe (ernstl-at-planet-dot-nl@ignore.this)
Date: 04/18/03


From: "Ernst Lippe" <ernstl-at-planet-dot-nl@ignore.this>
Date: Fri, 18 Apr 2003 23:01:34 +0200

On Fri, 18 Apr 2003 18:39:42 +0100, Dr. David Kirkby wrote:

> I've written a UNIX shell script
> http://www.medphys.ucl.ac.uk/~davek/teston
>
> that allows me to copy a software package to a remote machine, then
> try to configure and build the software on that remote host. So I
> might do something like this, to check package package-foo.tar.gz on 3
> machines with 4 different configuration options, with the -T option
> saying to do this is a unique directory.
>
> teston host1 -T package-foo
> teston host1 -c '--with-threads' -T package-foo
> teston host1 -c '--with-mpi' -T package-foo
> teston host1 -c '--without-gsl' -T package-foo
>
> teston host2 -T package-foo
> teston host2 -c '--with-threads' -T package-foo
> teston host2 -c '--with-mpi' -T package-foo
> teston host2 -c '--without-gsl' -T package-foo
>
> teston host3 -T package-foo
> teston host3 -c '--with-threads' -T package-foo
> teston host3 -c '--with-mpi' -T package-foo
> teston host3 -c '--without-gsl' -T package-foo
>
> so package-foo.tar.gz gets configure/built on 3 hosts, with 4
> different options to the configure script, in ****hopefully**** 4
> different directories on each host.
>
> My problem is that I need to put each set of file into a separate
> directory, as otherwise they mess each other up. Currently I'm using
> as a directory $HOME/$REMOTE_HOSTNAME/$PID, where $PID is the PID on
> the local machine from where this is started. There is no risk of
> files from host1 interfering with those of host2, since they are in
> different directories. But there is nothing preventing those with each
> different configuration option screwing each other up on the same
> host, as I can't guarantee the PIDs will be different each time.
>
> Hence I want a random number that is portable, so not relying on perl
> or /dev/random. It doesn't need to by crytograpically secure, but
> hopefully the risk of it producing the same number on the one system
> is very small (say < 1 in 10^5).
Why do you want to use a random number?

It seems much safer to use something like dir1, dir2 etc.
Before creating the directory you should check what the
the first free number is.

Another trick that should work in almost all cases is
to base the directory name on the current date and time
plus the PID of the process on the remote machine.
Unless the clock of that machine has serious problems
this should work in most cases.

greetings,

Ernst Lippe



Relevant Pages

  • Re: 0xc0040017 FWX E TCP NOT SYN PACKET DROPPED
    ... This is ISA reporting a host that's violating the rules of TCP. ... All TCP sessions should begin with a TCP-SYN packet and this one didn't do ... remote machine initiates a connection to the isaserver on Port 135 RPC ...
    (microsoft.public.isa.configuration)
  • Re: Remote debugging
    ... I disabled the firewall on the host and remote machine. ... saying:msvcmon.exe does not seem to be running on the target ...
    (microsoft.public.windowsxp.embedded)
  • Re: How can I get a random number in a UNIX shell script???
    ... > that allows me to copy a software package to a remote machine, ... > try to configure and build the software on that remote host. ... as I can't guarantee the PIDs will be different each time. ... plus the PID of the process on the remote machine. ...
    (comp.unix.shell)
  • Re: Remote debugging
    ... DCOM RPC is sitting on port 135. ... I can ping the system and telnet can open port 135 on the remote machine from the host machine. ... 'password' to fill-in although I don't have any password login in the target. ...
    (microsoft.public.windowsxp.embedded)
  • Re: How can I get a random number in a UNIX shell script???
    ... "Dr. David Kirkby" wrote: ... > that allows me to copy a software package to a remote machine, ... -- http://ftp.opensysmon.com is a shell script archive site with an open source system monitoring and network monitoring software package. ...
    (comp.unix.shell)