Skip to content

Instantly share code, notes, and snippets.

@mehdishahdoost
Created April 25, 2023 19:12
Show Gist options
  • Select an option

  • Save mehdishahdoost/1351c21b1f08149014c13e4e2c72f5a1 to your computer and use it in GitHub Desktop.

Select an option

Save mehdishahdoost/1351c21b1f08149014c13e4e2c72f5a1 to your computer and use it in GitHub Desktop.
Bash Script

List of shells on machine

cat /etc/shells

write and append to file

echo test > file.text
echo test2 >> file.txt

comment


#one-line comment

: '

more then one line comment

'

cat << endOfLine
line one
line two
line three
endOfLine

Read property file with bash

blue='\033[1;34m'
yellow='\033[1;33m'
nc='\033[0m'
echo -e "${blue} Kafka Brokers: ${nc}${yellow}"
grep kafka.brokers jboss/standalone/configuration/mq-kafka-loader.properties | awk -F= '{print $2}'
echo -e "${blue} Kafka Schema Registry: ${nc}${yellow}"
grep kafka.configuration.schema.registry.url  jboss/standalone/configuration/mq-kafka-loader.properties | awk -F= '{print $2}'
echo -e "${blue} Kafka NRT target: ${nc}${yellow}"
grep nrt.target.env jboss/standalone/configuration/mq-kafka-loader.properties | awk -F= '{print $2}'
echo -e "${blue} JDBC URL: ${nc}${yellow}"
grep -A 1 datasource.ods.connection-url jboss/standalone.properties
echo -e "${blue} STNI MQ: ${nc}${yellow}"
grep jms.queue.stni.destination jboss/standalone.properties | awk -F= '{print $2}'
echo -e "${blue} STNI2 MQ: ${nc}${yellow}"
grep jms.queue.stni2.destination jboss/standalone.properties | awk -F= '{print $2}'
echo -e "${blue} Event MQ: ${nc}${yellow}"
grep jms.queue.event.destination jboss/standalone.properties | awk -F= '{print $2}'
echo -e "${blue} Event2 MQ: ${nc}${yellow}"
grep jms.queue.event2.destination jboss/standalone.properties | awk -F= '{print $2}'
echo -e "${blue} Data-API JDBC: ${nc}${yellow}"
grep -A 1 spring.datasource.url wlp-ir-data-api/data-api/application-prod.properties
echo -e "${blue} Data-API Server port: ${nc}${yellow}"
grep server.port wlp-ir-data-api/data-api/application-prod.properties | awk -F= '{print $2}'

Print everything in table

blue='\033[1;34m'
yellow='\033[1;33m'
nc='\033[0m'
divider===============================
divider=$divider$divider
header="\n %-10s %20s\n"
format=" %-10s %20s\n"
width=43
kafka=$(grep kafka.brokers jboss/standalone/configuration/mq-kafka-loader.properties | awk -F= '{print $2}')
schemaReg=$(grep kafka.configuration.schema.registry.url  jboss/standalone/configuration/mq-kafka-loader.properties | awk -F= '{print $2}')
targetEnv=$(grep nrt.target.env jboss/standalone/configuration/mq-kafka-loader.properties | awk -F= '{print $2}')
jdbcUrl=$(grep -A 1 datasource.ods.connection-url jboss/standalone.properties)
stniDes=$(grep jms.queue.stni.destination jboss/standalone.properties | awk -F= '{print $2}')
stniDes2=$(grep jms.queue.stni2.destination jboss/standalone.properties | awk -F= '{print $2}')
eventDes=$(grep jms.queue.event.destination jboss/standalone.properties | awk -F= '{print $2}')
eventDes2=$(grep jms.queue.event2.destination jboss/standalone.properties | awk -F= '{print $2}')
dataApiJDBC=$(grep -A 1 spring.datasource.url wlp-ir-data-api/data-api/application-prod.properties)
dataApiPort=$(grep server.port wlp-ir-data-api/data-api/application-prod.properties | awk -F= '{print $2}')
printf "$header" "Key" "Value"
printf "%$width.${width}s\n" "$divider"
printf "$format" \ "Kafka Brokers" "$kafka" \
"Kafka Schema Registry" "$schemaReg" \
"Kafka BRT Target" "$targetEnv" \
"JDBC URL" "$jdbcUrl" \
"STNI Destination" "$stniDes" \
"STNI Destination2" "$stniDes2" \
"Event Destination" "$eventDes" \
"Event Destination2" "$eventDes2" \
"Data Api JDBC" "$dataApiJDBC" \
"Data API Port" "$dataApiPort"


Print folder size by pattern

input="tables2.txt"
while IFS= read -r line
do
  echo $line
  (du -bch *$line* 2>/dev/null | tail -1| awk '{print $1}') | sed s/"M"// >> result.txt
done < "$input"

Folder size calculation

######
#
# WLP-IR disk calculation
#
######

echo -e "${yellow}*** select operation ***${nc}"
echo "  1)Calculate with file exclusion"
echo "  2)Calculate directories size by pattern"
echo "  3)Calculate directories size by pattern and exclusion"
echo "  4)Calculate directories size by excat folder name exclusion"

read n


if [ $n -eq 1 ]; then

oldPath=$(pwd)
echo "Please enter path for calculation(ex: /app/wlp/nrt)"
read fileExPath
echo "Please enter file pattern exclusion. (ex: *.json)"
read excludeName

cd $fileExPath
du -sh --exclude=$excludeName

cd $oldPath
fi

if [ $n -eq 2 ]; then

oldPath=$(pwd)
echo "Please enter path for calculation(ex: /app/wlp/nrt)"
read fileExPath
echo "Please enter directory pattern. (ex: jb3)"
read dirPattern

cd .

du -bch *$dirPattern* | tail -1

cd $oldPath 

fi


if [ $n -eq 3 ]; then

oldPath=$(pwd)
echo "Please enter path for calculation(ex: /app/wlp/nrt)"
read fileExPath
echo "Please enter file pattern to exclude. (ex:*.json)"
read excludeName
echo "Please enter directory pattern. (ex: jb3)"
read dirPattern

cd $fileExPath

du -bch *$dirPattern* --exclude=$excludeName | tail -1

cd $oldPath

fi



if [ $n -eq 4 ]; then

oldPath=$(pwd)
echo "Please enter path for calculation(ex: /app/wlp/nrt)"
read fileExPath
echo "Please enter exact directory name to exclude. (ex: jb3)"
read dirPattern

cd $fileExPath

du -bch --exclude=$dirPattern | tail -1

cd $oldPath

fi

Read status code of url ( api - rest )

curl -k -LI https://tdfuji29s:7076 -o /dev/null -w '%{http_code}\n' -s

read properties key/value

grep {__GATEWAY_PORT__} gateway.properties.jboir6 | awk -F= '{print $2}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment