1

I'm new to shell scripts and i use the below code to run a spring boot, however i need to have a progress bar to show the progress of starting the application.

I have tried with echo "waiting to start" but need to have a progress bar to show.

cd /var/develop/eureka-discovery-services/target
pwd
java -jar eureka-discovery-services.jar &
while ! nc -z localhost 5001 ; do
echo "Waiting to start"
   sleep 2
done

cd /cd /var/develop/api-services/target
pwd
java -jar api-services.jar &
while ! nc -z localhost 6001 ; do
echo "Waiting to start"
   sleep 2
done
echo "All services started Successfully !!!"
Rabikatha
  • 249
  • 5
  • 9

1 Answers1

0

So basically its will be a little hack because you have no way to check the real progress of you starting process. Its more state between off/on. But if you still want to make the progress bar this code can do the job:

#!/bin/bash

function ProgressBar {
    let _progress=(${1}*100/${2}*100)/100
    let _done=(${_progress}*4)/10
    let _left=40-$_done
    _fill=$(printf "%${_done}s")
    _empty=$(printf "%${_left}s")
        # Progress : [########################################] 100%
        printf "\rProgress : [${_fill// /\#}${_empty// /-}] ${_progress}%%"

}

# Proof of concept
work1() {
        sleep 10
        nc -lp 5001
}
work2() {
        sleep 15
        nc -lp 6001
}

work1 &
progress=1
while ! nc -z localhost 5001 ; do
        ProgressBar ${progress} 100
        let progress=progress+1
        sleep 0.3
done
ProgressBar 100 100
echo ""
echo "Work 1 done"

work2 &
progress=1
while ! nc -z localhost 6001 ; do
        ProgressBar ${progress} 100
        let progress=progress+1
        sleep 0.3
done
ProgressBar 100 100
echo ""
echo "Work 2 done"

echo "All services started Successfully !!!"

Again its more Microsoft style progress bare here, we passing the job from x to 100 when nc report success. You can adjust the speed sleep 0.x

vx3r
  • 295
  • 1
  • 16