Re: variables in the run script

From: Wayne Marshall <wcm_at_b0llix.net>
Date: Tue, 8 Oct 2013 12:21:36 -0700

On Tue, 08 Oct 2013 20:12:06 +0200
Subba Rao <umroute_at_tanucoo.com> wrote:

> I have a run script that has an infinite loop performing some cleanup
> functions, system monitoring functions etc. Once the tasks in one
> loop cycle are completed, I want the loop in "run" script to sleep
> for some random #hours before starting a new loop cycle. I have been
> trying to use the $RANDOM in bash for the sleep time.
>
> while :
> do
> Function1
> Function2
> slp=$(( $RANDOM % 14 + 22)) /* Any number from 22 to 36 */
> zzz="${slp}h" /* Append "h" for hours */
> echo $zzz >> ./log.txt /* echo $zzz to log file */
> sleep $zzz /* sleep for $slp hours */
> done
>
> The problem is this script works fine when I test it in my home
> directory. When I put the code into "run" script, there is no value
> for $slp or $zzz.
>
> Can the "run" script have some bash code in it with some logic
> required for the service? How can I fix/implement this solution?
>
> Thank you in advance.
>
> Regards,
>
> Subbarao
>
>

No reason your script should work, nothing in the script
reassigns/updates $RANDOM.

Try this:

rnd=0
while :
do
     Function1
     Function2
     rnd=$((rnd % 14 + 22)) /* Any number from 22 to 36 */
     zzz="${rnd}h" /* Append "h" for hours */
     echo $zzz >> ./log.txt /* echo $zzz to log file */
     sleep $zzz /* sleep for $slp hours */
done


Wayne
Received on Tue Oct 08 2013 - 19:21:36 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:18 UTC