-3

I am trying to create a shell script where it should prompt and read the values as input and then update the same shell script with that value in a specific line and column.

Or if i can use another shell script to get the values and update original file.

i wanted to read and update below parameters values as input

USER=''user''
PASS=''password''
URL=''http://10.xxx.xxx.xxx:9206/MGR/status''
PORT1=''9204''
PORT2=''9206''

Full script

#!/bin/bash

USER=''user''

PASS=''password''

URL=''http://10.xxx.xxx.xxx:9206/MGR/status''

PORT1=''9204''
PORT2=''9206''

echo Metrics for $PORT1
echo =====================

maxthreads=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk  '{ print $4 }'`
echo Max Threads: $maxthreads

currentthreadcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk  '{ print $8 }'`
echo Current Threads: $currentthreadcount

busythreadcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk  '{gsub("<br>", "");print $12}'`
echo Busy Threads: $busythreadcount

maxprocesstime=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk  '{ print $16 }'`
echo Max Processing Time: $maxprocesstime

processtime=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk  '{ print $20 }'`
echo Processing Time: $processtime

requestcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk  '{ print $24 }'`
echo Request Count: $requestcount

errorcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT1}.* | awk  '{ print $27 }'`
echo Error Count: $errorcount

echo Metrics for $PORT2
echo =====================


maxthreads=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk  '{ print $4 }'`
echo Max Threads: $maxthreads

currentthreadcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk  '{ print $8 }'`
echo Current Threads: $currentthreadcount

busythreadcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk  '{gsub("<br>", "");print $12}'`
echo Busy Threads: $busythreadcount

maxprocesstime=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk  '{ print $16 }'`
echo Max Processing Time: $maxprocesstime

processtime=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk  '{ print $20 }'`
echo Processing Time: $processtime

requestcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk  '{ print $24 }'`
echo Request Count: $requestcount

errorcount=`curl -s -u ${USER}:${PASS} ${URL} | grep -o ${PORT2}.* | awk  '{ print $27 }'`
echo Error Count: $errorcount

My intension is not to edit the file and input values, instead read it as prompt and update the file in background.

Kenster
  • 23,465
  • 21
  • 80
  • 106
Jijo John
  • 61
  • 1
  • 7
  • 1
    But why? You can get input from the user of the script and then manage all of this with variables just as you are. But... it sounds like you want to hard code values in the script based on user input... in which case saving the user inputs to a config file separately and then calling up that config file within the original script would be the better option. – JNevill Jan 19 '22 at 15:28
  • 1
    Separately, fetching the same URL again for each variable is horribly inefficient. All of this could be easily refactored to a single `curl | awk` script. You also have a mound of [quoting errors.](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) Try http://shellcheck.net/ for help with those. – tripleee Jan 19 '22 at 15:31
  • Just to spell out what the first cnmment is trying to tell you, your script should accept the parameters as command-line arguments or options. In the simplest case, require the user to specify them all in fixed order, and then your script wall be simply `curl "$1:$2" "$3" | awk ...`; to add defaults, maybe change the order of the arguments and fall back with `"${2-defaultuser}:${3-defaultpass}"` – tripleee Jan 19 '22 at 16:13
  • Thanks Team. I did another method for achieving this using AWS secret manager. The code can read the data from secret manager. So our engineer can update the same in secret manager as a key value pair. Thank you all for the suggestion and help. I will further look into the option suggested to improve the code. – Jijo John Jan 21 '22 at 15:07

1 Answers1

0

Thanks Team. I did another method for achieving this using AWS secret manager. The code can read the data from secret manager. So our engineer can update the same in secret manager as a key value pair. Thank you all for the suggestion and help. I will further look into the option suggested to improve the code.

Jijo John
  • 61
  • 1
  • 7