Skip to content
Advertisement

prompt and read a value as input for shell script

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement