Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random line

Status
Not open for further replies.

mrn

MIS
Apr 27, 2001
3,993
GB
I'm writting a script to do an inital config of a HP-UX server, I've got to the NTP part and want to randomize the prefered server selection from 1 of 3 I.P's so all servers don;t have the same prefered NTP server.

I could do it with a count (1st IP, 2nd IP, 3rd IP) but wondered if anyone else could help with the random bit?

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
ok bit messy but could do this

a=`echo $RANDOM|cut -c 1`

if [ $a = "1" -o $a = "4" -o $a = "7" ]
then
IP1=192.168.1.1
elif [ $a = "2" -o $a = "5" -o $a = "8" ]
then
IP1=192.168.1.2
elif [ $a = "3" -o $a = "6" -o $a = "9" ]
then
IP1=192.168.1.3
fi

repeat for secondary IP

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
a=`echo $RANDOM|cut -c 1`

if [ $a = "1" -o $a = "4" -o $a = "7" ]
then
IP1=192.168.1.1
IP2=192.168.1.2
IP3=192.168.1.3
elif [ $a = "2" -o $a = "5" -o $a = "8" ]
then
IP1=192.168.1.2
IP2=192.168.1.3
IP3=192.168.1.1
elif [ $a = "3" -o $a = "6" -o $a = "9" ]
then
IP1=192.168.1.3
IP2=192.168.1.1
IP3=192.168.1.2
fi


Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Code:
r=$RANDOM
IP1=$((  r%3    + 1 ))
IP2=$(( (r+1)%3 + 1 ))
IP3=$(( (r+2)%3 + 1 ))

Annihilannic.
 
I neglected to include the "192.168.1." part, but you get my drift...

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top