I have a code where i want to install apt packages from a file, and logging the result.
If it succeds i want to print "< packagname > install: succes" and if it fails i need to write " < packagename > install: failed" and increment a variable called failed
I have populated the reqruiments.apt with fake apt package names to make it fail.
LOGFILE=log.txt
FAILED=0
for req in $(cat requirements.apt)
do
apt install -y "$req" &> aptInstall.log &&
printf "$req: Succes\n" >> $LOGFILE ||
(printf "$req: Failed\n" >> $LOGFILE && ((FAILED++)))
done
printf "\n\nApt install ran with $FAILED failed packages\n" >> $LOGFILE
printf "###############################\n" >> $LOGFILE
printf "\n\n" >> $LOGFILE
My log looks like this:
python-opencv-tre: Failed
build-essential-tre: Failed
python-scipy-tre: Failed
Apt install ran with 0 failed packages
###############################
I would have expected
python-opencv-tre: Failed
build-essential-tre: Failed
python-scipy-tre: Failed
Apt install ran with 3 failed packages
###############################