none
Batch file or similar more modern form of script ? RRS feed

  • Question

  • I need to create a batch file to do the following and I tried a bunch of things but I am not a programmer.

    1. I need to be able to specify the min and a max number.  I tried:

    FOR /L %X IN (100,1,102)

    I need to be able to capture the first 32 characters of  file and save in a variable

    In Linux this is:

    key=$(head -c 32 "c:\multiboinc\BOINC_$n\gui_rpc_auth.cfg"

    Then I need to start an application:

    something like this I think ??

    start "BOINC_%X" "c:\Program Files\BOINC\boinccmd.exe" --host 127.0.0.1:50%X --passwd $key --project wuprop.boinc-af.org/ detach

    I have others but if I can get this one working I should be able to change this one to fit the other cases.

    Your help is appreciated:

    Thursday, December 19, 2019 7:35 AM

Answers

  • OK thank you for the code that you supplied.  I do not know coding at all.  I figured how to do it in Bash scripting for my Linux machine but can't for windows.  I leave with my tail between my legs and convert anther Windows machine to Linux.

    #!/usr/bin/bash
    #!/bin/bash
    #!/bin/bash
    #
    #  Script Name nomorework.sh
    #
    helpFunction()
    {
       echo ""
       echo "Eg: sh nomorework.sh -a wuprop.boinc-af.org -b  BOINC-3"
       echo "Usage: $0 -a"
       echo -e "\t-a URL of the project that you want to detach without http://"
       echo -e "\t-b Name of the machine that you want to detach from eg (BOINC-3)"
           exit 1 # Exit script after printing help
    }
    
    while getopts "a:b:" opt
    do
       case "$opt" in
          a ) project_url="$OPTARG" ;;
          b ) machine="$OPTARG" ;;
    
          ? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
       esac
    done
    
    # Print helpFunction in case parameters are empty
    if [ -z "$project_url" ] || [ -z "$machine" ]
    then
       echo "Some or all of the parameters are empty";
       helpFunction
    fi
    
    n=100;
    max=101;
    while [ "$n" -le "$max" ]; do
        key=$(head -c 32 "/usr/bin/multiboinc/BOINC_$n/gui_rpc_auth.cfg"
    )
    echo $n $key
       /usr/bin/boinccmd --host 127.0.0.1:50$n --passwd $key --project $url nomorework
       n=`expr "$n" + 1`;
    done
    

    • Marked as answer by Dingo001 Thursday, December 19, 2019 8:36 AM
    Thursday, December 19, 2019 8:36 AM

All replies

  • $min = 1
    $max = 10
    
    $c32 = (Get-Content file.txt -Raw).Substring(0,32)
    


    \_(ツ)_/

    Thursday, December 19, 2019 7:55 AM
  • I have tried but it does not work, if this is the wrong forum then please direct me to the correct one as I need help.  I have been trying to figure this out for over four hours and I am sure someone can set me straight in a few minutes.

    I have just tried this:

    FOR /L %X IN (100,1,101) DO $c32 = (Get-Content c:\multiboinc\BOINC_%X\gui_rpc_auth.cfg -Raw).Substring(0,32)
    echo $c32
     DO start "BOINC_%X" "c:\Program Files\BOINC\boinccmd.exe" --host 127.0.0.1:50%X --passwd $c32 --project wuprop.boinc-af.org/ detach
    )

    But I got these errors:

    >FOR /L X IN (100,1,102) DO

    • Edited by Dingo001 Thursday, December 19, 2019 8:24 AM
    Thursday, December 19, 2019 8:14 AM
  • First the code is PowerShell and not CMD shell.

    You need to learn basic Windows first.

    This forum is not resourced to trach you basic things and it does not support conversion of scripts.  You must as a specific question bout a script you are writing and you must understand basic Windows technology.

    You cannot mix command shell with PowerShell.


    \_(ツ)_/

    Thursday, December 19, 2019 8:29 AM
  • OK thank you for the code that you supplied.  I do not know coding at all.  I figured how to do it in Bash scripting for my Linux machine but can't for windows.  I leave with my tail between my legs and convert anther Windows machine to Linux.

    #!/usr/bin/bash
    #!/bin/bash
    #!/bin/bash
    #
    #  Script Name nomorework.sh
    #
    helpFunction()
    {
       echo ""
       echo "Eg: sh nomorework.sh -a wuprop.boinc-af.org -b  BOINC-3"
       echo "Usage: $0 -a"
       echo -e "\t-a URL of the project that you want to detach without http://"
       echo -e "\t-b Name of the machine that you want to detach from eg (BOINC-3)"
           exit 1 # Exit script after printing help
    }
    
    while getopts "a:b:" opt
    do
       case "$opt" in
          a ) project_url="$OPTARG" ;;
          b ) machine="$OPTARG" ;;
    
          ? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
       esac
    done
    
    # Print helpFunction in case parameters are empty
    if [ -z "$project_url" ] || [ -z "$machine" ]
    then
       echo "Some or all of the parameters are empty";
       helpFunction
    fi
    
    n=100;
    max=101;
    while [ "$n" -le "$max" ]; do
        key=$(head -c 32 "/usr/bin/multiboinc/BOINC_$n/gui_rpc_auth.cfg"
    )
    echo $n $key
       /usr/bin/boinccmd --host 127.0.0.1:50$n --passwd $key --project $url nomorework
       n=`expr "$n" + 1`;
    done
    

    • Marked as answer by Dingo001 Thursday, December 19, 2019 8:36 AM
    Thursday, December 19, 2019 8:36 AM
  • Why convert. Just run your bash scripts on Windows use the bash shell for Windows: https://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bash-shell-on-windows-10/


    \_(ツ)_/

    Thursday, December 19, 2019 8:39 AM