- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: how to round robin a variable?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 06:01 AM
тАО06-05-2008 06:01 AM
clcnt=0
echo $COLORS |while read INCOLORS
do
(( clcnt +=1 ))
OUTCOLOR[$clcnt]=$INCOLORS
echo "$clcnt \c"
echo ${OUTCOLOR[$clcnt]}
done
1 #CC9999
2 #9999FF
3 #FFCC88
4 #FF99FF
5 #FFFF66
6 #FF9933
7 #CC9966
8 #990099
9 #006666
10 #993300
I now need to associate each color with a system that resides in $SysList so when I output the data to HTML I create a table and each cell represents a different system.
How can I associate this data to each lpar in $SysList - I will use the color to represent a system more than once.
any help is much appreciated as always :-)
Thanks
Chris.
Solved! Go to Solution.
- Tags:
- variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 06:16 AM
тАО06-05-2008 06:16 AM
Re: how to round robin a variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 06:43 AM
тАО06-05-2008 06:43 AM
Solution"sys1 sys2 sys3" for instance
typeset -i idxsys=0
typeset -i idxcol=0
for i in $Syslist
do
SYSNAME[$idxsys]=$i
SYSCOL[$idxsys]=${OUTCOLOR[$idxcol]}
idxsys=idxsys+1
idxcol=idxsys%${clcnt}
done
or you can
typeset -i idxsys=0
typeset -i idxcol=0
for i in $Syslist
do
eval "SYSCOL_${i}=${OUTCOLOR[$idxcol]}"
idxsys=idxsys+1
idxcol=idxsys%${clcnt}
done
Then you can use eval echo $"{SYSCOL_${i}}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 07:33 AM
тАО06-05-2008 07:33 AM
Re: how to round robin a variable?
We use the following snippet to randomly assign dbspaces at login time:
NUMBER=`date +%S | cut -c2,2`
set +A LINE_ARRAY `cat /etc/dbspace`
DBSPACETEMP=${LINE_ARRAY[$NUMBER]}
export DBSPACETEMP
where /etc/dbspace looks like this:
$ cat /etc/dbspace
dbs14 dbs13 dbs12 dbs11 dbs09 dbs10 dbs14 dbs13 dbs12
I think it would be simple to adapt this for your use.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 07:48 AM
тАО06-05-2008 07:48 AM
Re: how to round robin a variable?
You could use 'awk' to generate a random index into your array if you like:
# awk 'BEGIN{srand();printf("%d\n",(1+int(rand()*10)))}'
Regards!
...JRF...
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 08:17 AM
тАО06-05-2008 08:17 AM
Re: how to round robin a variable?
See:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1238236
What problem are you really trying to solve?
Once you have an lpar - color association, then how/where will that be used?
What will be the 'driver'?
That $SysList or something else still?
$ perl -e '@sys=<>; @colors=split /\s+/, $ENV{COLORS}; for $i (1..@sys) { print "$i $colors[$i-1] $sys[$i-1]" }' $SysList
1 #CC9999 aap
2 #9999FF noot
3 #FFCC88 mies
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 02:26 PM
тАО06-05-2008 02:26 PM
Re: how to round robin a variable?
Another way using Perl hashes (known in 'awk' as associative arrays):
# cat myref
#!/usr/bin/perl
use strict;
use warnings;
my $sys = shift or die "systemId expected\n";
my %colors = (
sys1 => '#CC9999',
sys2 => '#9999FF',
sys3 => '#FFCC88',
sys4 => '#FF99FF',
sys5 => '#FFFF66',
sys6 => '#FF9933',
sys7 => '#CC9966',
sys8 => '#990099',
sys9 => '#006666',
sys10 => '#993300'
);
if ( exists $colors{$sys} ) {
print "$colors{$sys}\n";
}
else {
print "#000000\n";
}
...run passing the "system" for which you want to find the color:
# ./myref sys3
#FFCC88
# ./myref badsys
#000000
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 04:45 PM
тАО06-05-2008 04:45 PM
Re: how to round robin a variable?
...and the last Perl solution hacked in 'awk':
# cat ./myref
#!/usr/bin/awk -f
END{
colors["sys1"]="#CC9999"
colors["sys2"]="#9999FF"
colors["sys3"]="#FFCC88"
colors["sys4"]="#FF99FF"
colors["sys5"]="#FFFF66"
colors["sys6"]="#FF9933"
colors["sys7"]="#CC9966"
colors["sys8"]="#990099"
colors["sys9"]="#006666"
colors["sys10"]="#993300"
if ($1 in colors)
print colors[$1]
else
print "#000000"
}
...run as:
# echo sys8 | ./myref
#990099
...oh, I so much prefer Perl :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2008 12:28 AM
тАО06-06-2008 12:28 AM
Re: how to round robin a variable?
I'll take a look at the exapmles and adapt for my purpose!
thanks again
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2008 06:03 AM
тАО06-06-2008 06:03 AM
Re: how to round robin a variable?
the solution that I found worked best to my skills and uderstanding:
for LPAR in $LparList
do
LPARNAME[$idlpar]=$LPAR
LPARCOL[$idlpar]=${outcolor[$idxcol]}
idlpar=idlpar+1
idxcol=idlpar%${clcnt}
done