Could some one help to find out what is problem with my for loop script. I'm trying to install packages from a list of variables using a for loop. My issues is when go grab the first package to be installed it and goes grab package from the list at the same time. Also it will install the packages all at the same time. How do I check fix it. I need to do one at a time.
REQPKGS="redhat-lsb-core telnet"
for pkg in $REQPKGS; do
if yum -q list installed "$REQPKGS" > /dev/null 2>&1; then
echo -e "$pkg is already installed"
else
yum install $REQPKGS -y
echo "Successfully installed $REQPKGS"
fi
done
Result of my script:
+ REQPKGS='redhat-lsb-core telnet'
+ for pkg in '$REQPKGS'
+ yum -q list installed 'redhat-lsb-core telnet'
+ yum install redhat-lsb-core telnet -y
+ echo 'Successfully installed redhat-lsb-core telnet'
Successfully installed redhat-lsb-core telnet
+ for pkg in '$REQPKGS'
+ yum -q list installed 'redhat-lsb-core telnet'
+ yum install redhat-lsb-core telnet -y
Loaded plugins: product-id, refresh-packagekit, rhnplugin, security, subscription-manager
This system is receiving updates from RHN Classic or RHN Satellite.
Setting up Install Process
Package redhat-lsb-core-4.0-7.el6.x86_64 already installed and latest version
Package 1:telnet-0.17-48.el6.x86_64 already installed and latest version
Nothing to do
+ echo 'Successfully installed redhat-lsb-core telnet'
Successfully installed redhat-lsb-core telnet
yum install $REQPKGS -y
on its own rather than thisfor
loop?yum
will skip over packages that are already installed on its own. – Centimane Sep 16 '16 at 15:43