Link to home
Start Free TrialLog in
Avatar of sunhux
sunhux

asked on

Help troubleshoot script with RANDOM variable

Whether I use the divide signs  /  or  %   it will keep giving me that "usage: sleep time"
error.   echo $randnm  will not echo anything.

I was sure it worked previously but all of a sudden it doesn't anymore

#!/bin/bash
#
randnm=$[ 1 + $[ RANDOM / 100 ]]
pattsigupd.sh[5]: 1:  not found
## rndnum=$[ 1 + $[ RANDOM % 100 ]]
sleep $randnm
usage: sleep time
#
echo $randnm
Avatar of ozo
ozo
Flag of United States of America image

What is on line 5 of pattsigupd.sh?
Avatar of sunhux
sunhux

ASKER

This error 1st appear on the original script below (1st 6-7 lines shown below):

#!/bin/bash
#
# pull updates from central server
#
rndnum=$[ 1 + $[ RANDOM % 100 ]]
sleep $rndnum
#


So line 5 is :
rndnum=$[ 1 + $[ RANDOM % 100 ]]
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sunhux

ASKER

Thanks, I'll test it out next Tue when back to office.


In the meantime, I have a new requirement in another link below;  if you can have a
look at it & provide sort of Shell or Perl script to be run in Solaris 10, will appreciate it:

https://www.experts-exchange.com/questions/28703371/Need-Shell-script-to-parse-thru-suitable-filesystems-files-folders-for-AV-scanning.html
Avatar of sunhux

ASKER

rndnum=$(( 1 + RANDOM % 100 ))

works fine