Sponsored Content
Full Discussion: Distribution of load
Top Forums Shell Programming and Scripting Distribution of load Post 302850911 by summer_cherry on Friday 6th of September 2013 02:53:29 AM
Old 09-06-2013
hope below perl can help you some

Code:
my %overload;
my %idle;

sub handle{
	OUTER:
	foreach my $os (sort keys  %overload){
		foreach my $is (sort keys %idle){
			my $ol = $overload{$os};
			my $available = $idle{$is};
			if($available > $ol){
				print "$os ",$ol," can be done on $is\n";
				$idle{$is} = $available - $ol;
				delete $overload{$os};
				next OUTER;
			}
			elsif ($available == $ol){
				print "$os ",$ol," can be done on $is\n";
				delete $overload{$os};
				delete $idle{$is};
				next OUTER;
			}
			else{
				print "$os ",$available," can be done on $is\n";
				delete $idle{$is};
				$overload{$os} = $ol-$available;
				next;
			}
		}
	}
}

sub remain{
	my @ol = keys %overload;
	if($#ol>=0){
		print "Still have below to be accormodated\n";
		foreach(@ol){
			print $_,":",$overload{$_},"\n";
		}
	}
	
	my @id = keys %idle;
	if($#id>=0){
		print "Still have below idle\n";
		foreach(@id){
			print $_,":",$idle{$_},"\n";
		}
	}
}

while(<DATA>){
	chomp;
	my @arr = split("-",$_);
	@arr = map {s/\s+//g;$_} @arr;
	if($arr[1] eq 'OverLoad'){
		$overload{$arr[0]}=$arr[2];
	}
	else{
		$idle{$arr[0]} =  $arr[2];
	}		
}

handle();

remain();
__DATA__
Server1 - OverLoad - 252
Server2 - OverLoad - 431
Server3 - AcceptLoad - 550
Server4 - AcceptLoad - 59
Server5 - AcceptLoad - 224
Server6 - OverLoad - 1000

 

5 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

could not load hme

After installing Solaris patches, i faced this problem which the system could not load hme ( network interface). after booting up the system i try to configure the IP add. on hme (ifconfig hme inet ......),but it fails. the /etc/hostname.hme0 file exists & is ok & in Prom mode also after running... (1 Reply)
Discussion started by: nikk
1 Replies

2. UNIX for Dummies Questions & Answers

Load error

hi i am facing a problem when i run a shell script to load a table.the error is Record 1: Rejected - Error on table TRENDS."SHP_CUST_ORD_ITM". ORA-14400: inserted partition key is beyond highest legal partition key Record 2: Rejected - Error on table TRENDS."SHP_CUST_ORD_ITM", column... (4 Replies)
Discussion started by: musavir19
4 Replies

3. UNIX for Dummies Questions & Answers

load Balance

Guys im trying to create a script that will load ballance 3 devices. Unix is still very alien to me having only been in this position for 3 months now. Not to mention the fact that i've been thrown in the deep end. Anyway so far i've managed to make a script that looks at all 4 devices and make a... (1 Reply)
Discussion started by: yorkyboy
1 Replies

4. Shell Programming and Scripting

Need help in wrting Load Script for a Load-Resume type of load.

hi all need your help. I am wrting a script that will load data into the table. then on another load will append the data into the existing table. Regards Ankit (1 Reply)
Discussion started by: ankitgupta
1 Replies

5. UNIX for Dummies Questions & Answers

VPS has load 200, httpd load no activity, netstat nothing

Hello, on my hostserver i see one VPS of mine got load of 200.00 and netstat nothing (not a single blank line on netstat command) after some time, netstat started showing connections, but i see no excessive IP connections. tail -f /var/log/httpd/access_log shows no activity /var/log/messages ;... (1 Reply)
Discussion started by: postcd
1 Replies
COLLATOR_ASORT(3)							 1							 COLLATOR_ASORT(3)

Collator::asort - Sort array maintaining index association

       Object oriented style

SYNOPSIS
public bool Collator::asort (array &$arr, [int $sort_flag]) DESCRIPTION
Procedural style bool collator_asort (Collator $coll, array &$arr, [int $sort_flag]) This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant. Array elements will have sort order according to current locale rules. Equivalent to standard PHP asort(3). PARAMETERS
o $coll -Collator object. o $arr -Array of strings to sort. o $sort_flag - Optional sorting type, one of the following: o Collator::SORT_REGULAR - compare items normally (don't change types) o Collator::SORT_NUMERIC - compare items numerically o Collator::SORT_STRING - compare items as strings Default $sort_flag value is Collator::SORT_REGULAR. It is also used if an invalid $sort_flag value has been specified. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 collator_asort(3)example <?php $coll = collator_create( 'en_US' ); $arr = array( 'a' => '100', 'b' => '50', 'c' => '7' ); collator_asort( $coll, $arr, Collator::SORT_NUMERIC ); var_export( $arr ); collator_asort( $coll, $arr, Collator::SORT_STRING ); var_export( $arr ); ?> The above example will output: array ( 'c' => '7', 'b' => '50', 'a' => '100', )array ( 'a' => '100', 'b' => '50', 'c' => '7', ) SEE ALSO
Collator constants, collator_sort(3), collator_sort_with_sort_keys(3). PHP Documentation Group COLLATOR_ASORT(3)
All times are GMT -4. The time now is 12:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy