bugy / script-server

Web UI for your scripts with execution management
Other
1.52k stars 244 forks source link

anyway to pass multiple arguments in a single bugy parameter? (i have a work around) #669

Open bob454522 opened 1 year ago

bob454522 commented 1 year ago

bugy v1.18 (and 1.17)-

Im trying to create a simple interface for a end user where a single parameter (type=text field) in bugy calls a bash script, that needs 4x arguments, ie i want bugy to execute exactly: ./myscript.sh arg1 arg2 arg3 arg4 (when my single type=Text Parameter contains exactly: arg1 arg2 arg3 arg4

In bugy, If i make a Parameter of Text or multi-Line text, and input exactly;

arg1 arg2 arg3 arg4
what gets executed is (note the single quotes):

./myscript.sh 'arg1 arg2 arg3 arg4'

(thus arg $1 = 'arg1 arg2 arg3 arg4' and arg$2 is blank/null.)

(FWIW- its a bit confusing that the bugy python scrolling log doesnt show this, as it shows: exactly what im looking for (ie it does not show the single quotes): 2023-05-04 12:22:19,307 [script_server.execution_service.INFO] Calling script #6: /home/myScript.sh arg1 arg2 arg3 arg4

(im hoping there is a solution or that im doing something wrong, i realize i could have 4x parameters, one each for arg1 arg2 arg3...

for now a workaround, that works, is the EXCELLENT feature bugy offers of: "Pass as stdin" with Stdin expected Text.

so what i do is - have the script echo the expected text, then read in bugys output (ie arg1 arg2 arg3 arg4) , then in the script i run the real script directly: ./RealScript.sh $readINvar

(without double quotes on readINvar, which gets me the correct execution with 4x args).

Im curious if im doing something wrong, or if there is a way to have 1x bugy parameter execute exactly what the user inputs (ie including spaces, and not adding single quotes around what is finally executed).

(if im not explaining this clearly, please see image below with the bash script behind it.)

thanks (and WOW is bugy excellent software!! thank you devs for your time and hard work on it!)

image example:

image

(and bash script behind this is:

image

`#!/bin/bash

location=$(echo "$1" | tr -cd [:alnum:]) unit=$(echo "$2" | tr -cd [:digit:]) apMac=$(echo "$3" | tr -cd [:alnum:]: | tr [:lower:] [:upper:])

echo "location: $location ( ssh ip: $sship )" echo "unit: $unit " echo "newAP MAC: $apMac "`

MNeill73 commented 1 year ago

Part of the shell-safeness of this system is that it doesn't let the target script "interpret" parameters. The way you've configured the script, it has one parameter. In effect, the interpreter quotes it, so that one single parameter is passed to the script. That's exactly what it should do.

You should either:

On Thu, May 4, 2023, 5:26 PM bob454522 @.***> wrote:

bugy v1.18 (and 1.17)-

Im trying to create a simple interface for a end user where a single parameter (type=text field) in bugy calls a bash script, that needs 4x arguments, ie i want bugy to execute exactly: ./myscript.sh arg1 arg2 arg3 arg4 (when my single type=Text Parameter contains exactly: arg1 arg2 arg3 arg4

In bugy, If i make a Parameter of Text or multi-Line text, and input exactly;

arg1 arg2 arg3 arg4 what gets executed is (note the single quotes):

./myscript.sh 'arg1 arg2 arg3 arg4'

(thus arg $1 = 'arg1 arg2 arg3 arg4' and arg$2 is blank/null.)

(FWIW- its a bit confusing that the bugy python scrolling log doesnt show this, as it shows: exactly what im looking for (ie it does not show the single quotes): 2023-05-04 12:22:19,307 [script_server.execution_service.INFO] Calling script #6 https://github.com/bugy/script-server/issues/6: /home/myScript.sh arg1 arg2 arg3 arg4

(im hoping there is a solution or that im doing something wrong, i realize i could have 4x parameters, one each for arg1 arg2 arg3...

for now a workaround, that works, is the EXCELLENT feature bugy offers of: "Pass as stdin" with Stdin expected Text.

so what i do is - have the script echo the expected text, then read in bugys output (ie arg1 arg2 arg3 arg4) , then in the script i run the real script directly: ./RealScript.sh $readINvar

(without double quotes on readINvar, which gets me the correct execution with 4x args).

Im curious if im doing something wrong, or if there is a way to have 1x bugy parameter execute exactly what the user inputs (ie including spaces, and not adding single quotes around what is finally executed).

(if im not explaining this clearly, please see image below with the bash script behind it.)

thanks (and WOW is bugy excellent software!! thank you devs for your time and hard work on it!)

image example: (and bash script behind this is: `

!/bin/bash

location=$(echo "$1" | tr -cd [:alnum:]) unit=$(echo "$2" | tr -cd [:digit:]) apMac=$(echo "$3" | tr -cd [:alnum:]: | tr [:lower:] [:upper:])

echo "location: $location ( ssh ip: $sship )" echo "unit: $unit " echo "newAP MAC: $apMac " `

[image: image] https://user-images.githubusercontent.com/60830628/236332832-40a192a0-20c5-47c5-ae87-34d252660fbb.png

— Reply to this email directly, view it on GitHub https://github.com/bugy/script-server/issues/669, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3HBI3TLB6HQTSALUB6Z5JDXEQNILANCNFSM6AAAAAAXWKQKOY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

chellige commented 1 year ago

Add something like this to the top of your script. Then you can call the parameters by name in any order:

**

Loop through startup arguments

while [[ $# -gt 0 ]] ; do key="$1" case $key in --location|-l) location="$2" shift ; shift # pass argument, then pass value ;; --unit|-u) unit="$2" shift ; shift # pass argument, then pass value ;; --mac|-m) apMac="$2" shift ; shift # pass argument, then pass value ;;
*) # unknown option echo "Error: $1 is not a valid option." shift # pass argument ;; esac done **

echo "The location is: ${location}" echo "The Unit is: ${unit}" echo "The apMac is ${apMac}"

$ ./test.sh -u "Unit 12" -l hawaii -m abc123 The location is: hawaii The Unit is: Unit 12 The apMac is abc123

$ ./test.sh --unit "Unit 13" --location detroit --mac "XYZabc" The location is: detroit The Unit is: Unit 13 The apMac is XYZabc

bugy commented 1 year ago

Hi @bob454522 this is not supported, unfortunately.

But for your use case, i would recommend to go with 4 separate parameters, since your script expects exactly 4 words. So you can make 4 parameters and make all of them required. As another workaround, you can also apply recommendations from above (for example, split the arg inside the script)

But I will keep this request in a backlog, there are some scenarios when the parameters count might be dynamic. If anyone wants to implement it, it should be rather simple.

MNeill73 commented 1 year ago

while [[ $# -gt 0 ]] ; do key="$1" case $key in --location|-l) location="$2" shift ; shift # pass argument, then pass value ;; --unit|-u) unit="$2" shift ; shift # pass argument, then pass value ;; --mac|-m) apMac="$2" shift ; shift # pass argument, then pass value ;; *) # unknown option echo "Error: $1 is not a valid option." shift # pass argument ;; esac done

while getopts "l:u:m:" opt; do case "${opt}" in l) location=${OPTARG};; u) unit=${OPTARG};; m) apMac=${OPTARG};;

getopts is much more powerful, does the looping itself, and generates "bad argument" errors internally.

https://www.computerhope.com/unix/bash/getopts.htm

On Thu, May 4, 2023 at 8:47 PM chellige @.***> wrote:

Add something like this to the top of your script. Then you can call the parameters by name in any order:

`

!/bin/bash

Loop through startup arguments

while [[ $# -gt 0 ]] ; do key="$1" case $key in --location|-l) location="$2" shift ; shift # pass argument, then pass value ;; --unit|-u) unit="$2" shift ; shift # pass argument, then pass value ;; --mac|-m) apMac="$2" shift ; shift # pass argument, then pass value ;; *) # unknown option echo "Error: $1 is not a valid option." shift # pass argument ;; esac done

echo "The location is: ${location}" echo "The Unit is: ${unit}" echo "The apMac is ${apMac}" ` $ ./test.sh -u "Unit 12" -l hawaii -m abc123 The location is: hawaii The Unit is: Unit 12 The apMac is abc123

$ ./test.sh --unit "Unit 13" --location detroit --mac "XYZabc" The location is: detroit The Unit is: Unit 13 The apMac is XYZabc

— Reply to this email directly, view it on GitHub https://github.com/bugy/script-server/issues/669#issuecomment-1535564580, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3HBI3VEC2HJLRGPTRCGUI3XEREZNANCNFSM6AAAAAAXWKQKOY . You are receiving this because you commented.Message ID: @.***>

bob454522 commented 1 year ago

Thank you all for the great replies- I understand why bugy was setup to specifically not allow what i wanted to do (for safety).

The getopts solution is a great one, and is what i went with. It still allows me accomplish exactly what i originally wanted (that is have my end user paste into bugy ONCE, a ONE line copy/paste of "multiple arguments" (from a auto generated spreadsheet), and have that one line be parsed for multiple arguments. over in the bash script.

While im all good now (thanks!) - i could see future scenarios where someone may want to "Raw input" exactly what they input into the bugy webGui -> into their shell script. (perhaps the user could enabled this via a option in the type=Multi-Line_text parameters section, along with a warning about its safety).

My bugy is only accessible on our private/internal network (as i assume most bugy installs are setup)

I would contribute this feature to bugy's codebase if i had the ability, so instead i will make a donation to support this great work. thank you again

bugy commented 1 year ago

Hey @bob454522, I fully agree with you, there could be cases, when arguments split would be helpful. So I would keep this ticket open, if anyone else will need it too

so instead i will make a donation to support this great work

Thank you!

PS the tool is called Script server :sweat_smile: "bugy" is my username on github