Author Topic: My Awesome Batch File Loop Menu (cgMiner on Win7)  (Read 5780 times)

Offline PandaMiner

  • Jr. Member
  • **
  • Posts: 100
  • David
    • Silver Investor
My Awesome Batch File Loop Menu (cgMiner on Win7)
« on: September 30, 2012, 09:30:16 PM »
I have taken a page from KANO's book and decided to put my cgMiner on a loop.

I have been experimenting with the commands and colors and have something I think is worthy of sharing.  I want your opinions and critique, and if you'll be using this for your mining operations.

After starting cgMiner with this batch file, and then you [Q]uit cgMiner, you'll get the menu (screen 1)
 If you select [C]ancel at this menu, you'll see the 2nd screen (black),
 If you select [G]o, then you'll see it start up again (screen 3)
 If you select nothing, after the WAIT time, it will select [G]o for you.



Code: [Select]
@ECHO OFF
REM file name: looper.bat
REM version: 1.0
set SLEEP=15

:LOOP
cls
color 0C
echo Starting cgMiner Loop . . .
Set NOW=%date:~10,4%-%date:~4,2%-%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%
Set PARAM0=--scrypt -I 12,16 -g 1 --shaders 800,1120 --no-submit-stale
Set PARAM1=--auto-fan --gpu-fan 0-60,0-60 --auto-gpu --gpu-engine 800-925,820-900
Set PARAM2=--gpu-memclock 1050,1000 --temp-target 80 --temp-overheat 85 --temp-cutoff 95
Set PARAM3=-o http://litecoinpool.org:9332 -u Panda.1 -p 1 --failover-only -o http://notroll.in:6332 -u Panda47.failover1 -p 12345
Set PARAM4=--api-network --api-listen --api-allow W:127.0.0.1,W:192.168.1.0/24 --api-description 5830_and_6790
Set PARAM5=2> "miner-session.%NOW%.log"
c:\users\dave\desktop\litecoin\cgminer275\cgminer %PARAM0% %PARAM1% %PARAM2% %PARAM3% %PARAM4%
GOTO MENU


:MENU
color 1F
cls
echo * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo.
echo *                             cgMiner Loop                                    *
echo.
echo * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo.
echo *      MENU:                                                                  *
echo.
echo *       C - Cancel the loop                                                   *
echo.        G - Go now (Don't wait the %SLEEP% seconds.)
echo *                                                                             *
echo.
echo *                                                                             *
echo.
echo *                                                                             *
echo.       - Writing log file:   miner-session.%NOW%.log
echo *                                                                             *
echo.
echo * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
echo.

choice /C cg /N /T %SLEEP% /D g /M "Restarting cgMiner in %SLEEP% seconds. (C)ancel or (G)o now?: "
IF errorlevel 255 goto :EOF
IF errorlevel 2 goto LOOP
IF errorlevel 1 goto CANCEL
IF errorlevel 0 goto LOOP
goto :EOF

:CANCEL
color 0F
cls
echo Mining Operation has been canceled.
echo Log written as: miner-session.%NOW%.log

Now let me explain how it works

set SLEEP=15

This is how long to WAIT for the user to select an option.  Right now this is hard coded, as I don't see a reason to make it dynamic right now.



:Loop
cls
color 0C
echo Starting cgMiner Loop . . .


This is the start of the loop, it clears the screen then changes the terminal color to Bright Red on Black, then outputs a message.




Set NOW=%date:~10,4%-%date:~4,2%-%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%

This sets the variable "now" equal to the current date and time in this format: YYYY-MM-DD_HHMMSS




Set PARAM0=--scrypt -I 12,16 -g 1 --shaders 800,1120 --no-submit-stale
Set PARAM1=--auto-fan --gpu-fan 0-60,0-60 --auto-gpu --gpu-engine 800-925,820-900
Set PARAM2=--gpu-memclock 1050,1000 --temp-target 80 --temp-overheat 85 --temp-cutoff 95
Set PARAM3=-o http://litecoinpool.org:9332 -u USER.1 -p 1 --failover-only -o http://notroll.in:6332 -u USER.1 -p 12345
Set PARAM4=--api-network --api-listen --api-allow W:127.0.0.1,W:192.168.1.0/24 --api-description <SOME DESCRIPTION HERE>
Set PARAM5=2> "miner-session.%NOW%.log"


These set up variables that are later used to pass information to cgminer.  I did this because I don't like to scroll horizontally every time I want to tweak the settings.  This way I see them all at the same time (for the most part), and work on them.

I tried to keep each set of parameters that are related to each other on the same variable.  Param4 turns on the API stuff, Param5 writes out the log. Notice that the name of the log file is dynamic, based on the variable "now" that we set up earlier.




c:\users\dave\desktop\litecoin\cgminer275\cgminer %PARAM0% %PARAM1% %PARAM2% %PARAM3% %PARAM4%

Since windows throws us to our user folder when we run the Command Shell (cmd.exe) I decided to keep the looper.bat file here, and use full paths for the program. Feel free to change this portion.

Here you see that I start cgMiner.exe (we don't need the extension in the batch file) with all of the parameters that we set up earlier. The order doesn't matter, but I like to keep it organized. Make sure to leave a space between the %variable-tokens%!




:MENU
color 1F
cls


This starts the menu section. It changes the color to Bright White on Blue, then clears the screen.  After this is just a bunch of echo statements that "paint" the menu.




choice /C cg /N /T %SLEEP% /D g /M "Restarting cgMiner in %SLEEP% seconds. (C)ancel or (G)o now?: "

This is the bread-and-butter of the menu system.  It uses the CHOICE command.
    [*] /C cg - The choices are "c" and "g" (not case sensitive),
    [*] /N - do not show us the choices in a prompt
    [*] /T %SLEEP% - Wait the amount of [t]ime in the specified number of SECONDS
    [*] /D g - Default selection is "g" (must be part of the /Choices)
    [*] /M "string" - Outputs a message string.
    [/list]




    IF errorlevel 255 goto :EOF
    IF errorlevel 2 goto LOOP
    IF errorlevel 1 goto CANCEL
    IF errorlevel 0 goto LOOP


    The CHOICE command terminates with some type of error level number.  We are testing what was selected, and also making sure it doesn't fail.  The choices given with /C are numbered from left to right, starting with 1.  In our case, we only had 2 choices, and they are C and G, so we test for 1 or 2, respectively.

    When testing errorlevels, you do them in desending form, otherwise they will RUN each command up to and including the correct error level!

    255 = Operation was terminated, or otherwise failed.
    2 = user selected "g", so go to the section marked :loop
    1 = user selected "c", so go to the section marked :cancel
    0 = Operation was terminated without an error level, so we'll just restart the loop




    goto :EOF

    This just means "end of file" and tells the shell to go to the end of the file and exit.  We put that here in case our batch file process is interrupted while checking for error levels, and is a friendly way to end the script, gracefully. It also serves to close our section.




    :CANCEL
    color 0F
    cls
    echo Mining Operation has been canceled.
    echo Log written as: miner-session.%NOW%.log


    Our last section to do something when user selects to cancel the loop.  It changes the color to Bright White on Black, clears the screen, and outputs information.



    What do you guys think?  Any suggestions?
    « Last Edit: September 30, 2012, 10:30:39 PM by PandaMiner »
    ~Dave~

    Offline Malak

    • Sr. Member
    • ****
    • Posts: 570
    Re: My Awesome Batch File Loop Menu (cgMiner on Win7)
    « Reply #1 on: April 12, 2013, 01:18:35 PM »
    Impressive batch programming. Lots to learn here. Could be very useful to all of us newbies.
    LTC: LdxgJQLUdr8hZ79BV5AYbxkBUdaXctXAPi

    Kamikaze Game: http://litecoinkamikaze.com/ref/8317

    Offline Shad3d

    • Jr. Member
    • **
    • Posts: 32
    • Interesting...
    Re: My Awesome Batch File Loop Menu (cgMiner on Win7)
    « Reply #2 on: April 13, 2013, 03:50:29 PM »
    Excellent work,sir...excellent work!
    Donate: LWaMc7SafccTNPxbeFjVhVMwv1oCSct3r2
    Thanks!

    Offline DBG

    • Newbie
    • *
    • Posts: 19
    Re: My Awesome Batch File Loop Menu (cgMiner on Win7)
    « Reply #3 on: May 12, 2013, 12:28:11 PM »
    Awesome script Panda, my only possible suggestion would be to add a TITLE function into the batch.  In fact if you implement it after the loop jump you can even have it pass on params.  So instead of having it say "C:\Windows\System32\cmd.exe" or what have you, the title could be "cgminer %VERSION% - mining at %HASHRATE%" or whatever you want to extract from the long list of configurable elements.

    Offline ncvf1980

    • Newbie
    • *
    • Posts: 1
    Re: My Awesome Batch File Loop Menu (cgMiner on Win7)
    « Reply #4 on: August 27, 2013, 12:27:53 PM »
    Awesome batch file!!
    Would you happen to know how to hide the command prompt?
    I have tried with wscript and hstart and it hasnt worked for me
    Thx