i'm trying change directory , run additional commands within whiptail
dialog screen, after cloning git repository seems script dying when trying change directory:
status=0 touch log.txt while [ $status -lt "100" ]; echo "cloning repo" >> log.txt git clone git@git.bitbucket.org:abc/repo.git /repo >> log.txt 2>&1 echo "changing directory" >> log.txt cd /repo >> log.txt 2>&1 echo `pwd` echo "installing bundler" >> log.txt gem install bundler --no-ri --no-rdoc >> log.txt 2>&1 (( status += 99 )) echo $status done | whiptail --gauge "setting neo (this take time)..." 40 78 0 ;;
logging commands set -x
, looks like:
:66+status=0 :67+touch log.txt :149+whiptail --gauge 'setting (this take time)...' 40 78 0 :68+'[' 0 -lt 100 ']' :71+echo 'apt-get update' :73+(( status += 15 )) :74+echo 15 :77+echo 'apt-get upgrade' :79+(( status += 15 )) :80+echo 30 :83+echo 'apt-get -y git-all' :85+(( status += 15 )) :86+echo 45 :111+(( status += 30 )) :112+echo 75 :115+rm -rf /repo :116+echo 'cloning repo' :117+git clone git@git.bitbucket.org:abcd/repo.git /repo :118+echo 'changing directory' :119+cd /repo ::120+pwd :120+echo /repo :121+echo 'installing bundler' :122+gem install bundler --no-ri --no-rdoc :148+echo 100 :68+'[' 100 -lt 100 ']' :5+true ::11+whiptail --title 'configuration menu' --menu 'choose option' 40 78 30 1 'show current configuration.' 2 'setup wizard.' 0 exit
the output of log.txt
stops @ changing directory
, whiptail menu goes main page (as if setup done, it's not since should see pwd
, installing bundler
in log too):
cloning repo cloning '/repo'... changing directory
i'm not getting errors diagnosing what's going on posing problem me. appreciated!
because you're using >>log.txt
on each command, log file being re-opened every command -- meaning using cd
changes directory in logfile being created.
to fix this, at top of script, use:
exec 3>log.txt
...and, whenever want write file, append >&3
each command write previously-opened file descriptor.
Comments
Post a Comment