Batch file help.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
redtab
Posts: 4
Joined: 06 Nov 2012 18:36

Batch file help.

#1 Post by redtab » 06 Nov 2012 18:46

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file help.

#2 Post by foxidrive » 06 Nov 2012 22:08

Do you get the nodes of the cluster's ip addresses from a file, or how?

redtab
Posts: 4
Joined: 06 Nov 2012 18:36

Re: Batch file help.

#3 Post by redtab » 07 Nov 2012 10:27

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).

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file help.

#4 Post by foxidrive » 07 Nov 2012 10:37

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

redtab
Posts: 4
Joined: 06 Nov 2012 18:36

Re: Batch file help.

#5 Post by redtab » 07 Nov 2012 11:48

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?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file help.

#6 Post by foxidrive » 07 Nov 2012 22:55

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.

redtab
Posts: 4
Joined: 06 Nov 2012 18:36

Re: Batch file help.

#7 Post by redtab » 08 Nov 2012 06:03

Thanks for that. I hadn't quite picked up when spaces counted.

Post Reply