Godzilla74 Godzilla74 - 3 months ago 17
Linux Question

Whiptail is not running my bash commands

I've created a bash program using

whiptail
to give a graphical type interface to the user to setup their system. For some reason my script isn't running any of my bash commands though, instead it seems to be cycling through outputting to my
log.txt
file, but no packages are being installed.

STATUS=0
touch log.txt
while [ $STATUS -lt 100 ]; do
# update apt repos
apt-get update
wait
echo "apt-get update" >> log.txt
let STATUS=STATUS+15
echo $STATUS
# update apt package
apt-get upgrade
wait
echo "apt-get upgrade" >> log.txt
let STATUS=STATUS+15
echo $STATUS
# install required packages
apt-get -y git-all nmap hydra
wait
echo "apt-get -y git-all nmap hydra" >> log.txt
let STATUS=STATUS+10
echo $STATUS
# install rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
wait
echo "cloning rbenv" >> log.txt
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'exporting PATH' >> log.txt
~/.rbenv/bin/rbenv init
wait
echo 'initializing rbenv' >> log.txt
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
wait
echo "cloning ruby-build" >> log.txt
rbenv install 2.1.4
wait
echo "installing ruby 2.1.4" >> log.txt
let STATUS=STATUS+25
echo $STATUS
done | whiptail --gauge "Setting Up Neo (THIS WILL TAKE SOME TIME)..." 40 78 0


So, to confirm my while loop is actually running, I started echoing things to
log.txt
. Here is the output:

apt-get update
apt-get upgrade
apt-get -y git-all nmap hydra
cloning rbenv
exporting PATH
initializing rbenv
cloning ruby-build
installing ruby 2.1.4


What have I done wrong?

Answer

First, since you have no backgrounded processes, wait is not doing anything.

Second, since whiptail is reading stdin, you need to ensure that stdout from all apt-get, git, rbenv, etc commands are redirected to stderr, or better, to your log.

    # update apt repos
    echo "apt-get update" >> log.txt
    apt-get update >>log.txt 2>&1
    (( STATUS += 15 ))
    echo $STATUS

    # update apt package
    echo "apt-get upgrade" >> log.txt
    apt-get upgrade >> log.txt 2>&1
    (( STATUS += 15 ))
    echo $STATUS

and so on.

Comments