Hey, I'm fairly new to batch file writing, and I'm trying to write a batch file that finds a node on a cluster with the least load and returns, or returns the first node it finds with zero load.
I'm using PUTTY's plink to run "uptime" on each node of the cluster, and my plan was to use FIND "load average 0.00" to identify that the node has no load, and that I should use that node (so it stops checking nodes then). I really don't know how I would capture the load times and compare them to find the best one.
Could anyone help me with this? I've tried to explain things as best I can, but let me know if I need to clarify.
Best.
Batch file help.
Moderator: DosItHelp
Re: Batch file help.
Do you get the nodes of the cluster's ip addresses from a file, or how?
Re: Batch file help.
The command I am running is this:
plink login@host.edu "rsh c2node%%N uptime"
Where %%N is the current node number in the FOR loop going from 8 to 2.
The output from the command looks like this:
HH:MMam up nn days HH:MM, X users, load average: X.XX, X.XX, X.XX
All I'm really looking to check is the first number after "load average:". I want to use either the node with the lowest value, or the first node to read 0.00 (most nodes are at 0.00, most of the time).
plink login@host.edu "rsh c2node%%N uptime"
Where %%N is the current node number in the FOR loop going from 8 to 2.
The output from the command looks like this:
HH:MMam up nn days HH:MM, X users, load average: X.XX, X.XX, X.XX
All I'm really looking to check is the first number after "load average:". I want to use either the node with the lowest value, or the first node to read 0.00 (most nodes are at 0.00, most of the time).
Re: Batch file help.
Try this command on the output of the for loop, so that the first one to return 0.xx percent will cause the loop to exit and goto the label where you perform the actual task, and use the %val% from the loop.
Code: Select all
find "load average: 0." >nul && set val=%%N& goto :ProcessTheTask
Re: Batch file help.
Thanks a lot! What I currently have is this:
FOR %%N IN (8 7 6 5 4 3 2) DO (
plink username@hostname "rsh c2node%%N uptime" | FIND "load average: 0.00" >nul
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 set node=%%N& goto :FoundNode
)
:NodeNotFound
set node =8
:FoundNode
Stuff to do
Does this seem like the best way to do this?
FOR %%N IN (8 7 6 5 4 3 2) DO (
plink username@hostname "rsh c2node%%N uptime" | FIND "load average: 0.00" >nul
IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 set node=%%N& goto :FoundNode
)
:NodeNotFound
set node =8
:FoundNode
Stuff to do
Does this seem like the best way to do this?
Re: Batch file help.
redtab wrote::NodeNotFound
set node =8
You are setting node plus a space to 8 in the above.
If you are searching for an unloaded machine then it seems ok.
Re: Batch file help.
Thanks for that. I hadn't quite picked up when spaces counted.