Skip to content

Instantly share code, notes, and snippets.

@shah-smit
Created July 6, 2018 12:56
Show Gist options
  • Save shah-smit/fda01ee9849c193717a2e1d1162cf98c to your computer and use it in GitHub Desktop.
Save shah-smit/fda01ee9849c193717a2e1d1162cf98c to your computer and use it in GitHub Desktop.
I wrote my first Bash Script with a updating Loader.
#!/bin/bash
# Author : Teddy Skarin
# 1. Create ProgressBar function
# 1.1 Input is currentState($1) and totalState($2)
function ProgressBar {
# Process data
let _progress=(${1}*100/${2}*100)/100
let _done=(${_progress}*4)/10
let _left=40-$_done
# Build progressbar string lengths
_done=$(printf "%${_done}s")
_left=$(printf "%${_left}s")
_mes=$(printf "Okay")
# 1.2 Build progressbar strings and print the ProgressBar line
# 1.2.1 Output example:
# 1.2.1.1 Progress : [########################################] 100%
printf "\r Progress : [${_done// /#}${_left// /-}] ${_progress}%%"
}
# Variables
_start=1
# This accounts as the "totalState" variable for the ProgressBar function
_end=100
# Variables
_starttwo=1
# This accounts as the "totalState" variable for the ProgressBar function
_endtwo=50
# Proof of concept
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n'
printf '\n Waiting for a transaction \n'
sleep 5
printf '\n Booking Request Recieved \n'
printf '\n Hotel Name: HDAC Boutique Hotel \n'
printf '\n Large Double Room \n'
printf '\n From: 05/07/2018 \n'
printf '\n To: 07/07/2018 \n'
printf '\n Capacity: 2 person \n'
sleep 17
printf '\n Processing Transaction \n'
for number in $(seq ${_start} ${_end})
do
sleep 0.01
ProgressBar ${number} ${_end}
done
printf '\n Transaction Created \n'
printf '\n TxId: 1d90fe664164cb5bdc02aca140a96cd779973c810bfeb5bb18669adf88f5704b \n'
printf '\n Awating confirmation \n'
for number in $(seq ${_starttwo} ${_endtwo})
do
sleep 1
ProgressBar ${number} ${_endtwo}
done
printf '\n Transaction Confirmed \n'
printf '\n {
"balance" : {
"amount" : -300.01000000,
"assets" : [
]
},
"myaddresses" : [
"HHQCvoMksJShQNcjAKX4esnafw8c7eSoXK"
],
"addresses" : [
"H7neUvorvia9y37FvPDv8U6CjErMG5knTB"
],
"permissions" : [
],
"items" : [
],
"data" : [
],
"confirmations" : 6,
"blockhash" : "11844888364f449a8a9c13c2f0835a682f95f81aac13d5be1bc609a261f6b4b2",
"blockindex" : 1,
"blocktime" : 1530747592,
"txid" : "1d90fe664164cb5bdc02aca140a96cd779973c810bfeb5bb18669adf88f5704b",
"valid" : true,
"time" : 1530747453,
"timereceived" : 1530747453
} \n'
printf '\n Transaction Completed \n'
printf '\n Waiting for a transaction \n'
sleep 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment