top of page

Simple shell script to download a list of Packages with Versions in to a directory in RedHat Linux

  • Writer: Sankalpa H.T.S
    Sankalpa H.T.S
  • Jun 27, 2022
  • 2 min read

ree


Let's assume that in your organization the technical team is giving you a list of Packages with Versions in a file and ask you to download them. What are you going to do? Are you going to download them one by one? Then we might think, whether it is possible to download all of them in one single shot. Yes it's possible.


You are receiving below list of packages with versions in a file.

acl-2.2.51-15.el7.x86_64

basesystem-10.0-7.el7.noarch

chkconfig-1.7.6-1.el7.x86_64

dbus-1.10.24-15.el7.x86_64

e2fsprogs-1.42.9-19.el7.x86_64

findutils-4.5.11-6.el7.x86_64

gawk-4.0.2-4.el7_3.1.x86_64

hardlink-1.0-19.el7.x86_64

ipmitool-1.8.18-9.el7_7.x86_64

jansson-2.10-1.el7.x86_64


Below are my machine information such as OS, Kernel and the Architecture.

ree

Firstly, I'm going to create a directory inside the root directory. Please choose wherever you want to create and what name should be as your wish.

# mkdir /root/download_packages

Make sure it is created.

# cd /root/
# ls -ltr
ree

Go to the created directory and make a txt file named "Package_List_with_Versions.txt".

# cd /root/download_packages/
# touch Package_List_with_Versions.txt
# ls -ltr
ree

Now copy the Package list from the received file and paste it into the newly created file.

# vi Package_List_with_Versions.txt
ree

Then save it using "esc" + ":" + "wq!".

# cat Package_List_with_Versions.txt 
ree

Now let's create the shell script file.

# touch download_rpms_list.sh
# vi download_rpms_list.sh

Then add below line of code to it and save.

#!/bin/sh

while read -r line
do
echo "Package-->$line"
yum install --downloadonly --downloaddir=/root/download_packages/download_rpms/PKGS/ -y $line
done < Package_List_with_Versions.txt

# cat download_rpms_list.sh
ree

# chmod 755 download_rpms_list.sh
# ls -ltr
ree

Hold on!


Not all are done yet. Now


You can simply run the shell script.

# ./download_rpms_list.sh

And then check whether the packages are downloaded or not into the specified location of "/root/download_packages/download_rpms/PKGS/" as in the shell script.



This script will try to download only the packages which are not already installed in the system.


What about the packages listed in the file but already installed in the system? How are we going to download them as well?


It is quiet simple. All you need to do is change the yum install into yum reinstall in the shell script.

#!/bin/sh

while read -r line
do
echo "Package-->$line"
yum reinstall --downloadonly --downloaddir=/root/download_packages/download_rpms/PKGS/ -y $line
done < Package_List_with_Versions.txt

# cat download_rpms_list.sh
ree

Again run the shell script in the same way.

# ./download_rpms_list.sh

And check whether the packages are downloaded or not into the specified location of "/root/download_packages/download_rpms/PKGS/" as in the shell script.


# ls -ltr download_rpms/PKGS/
ree


That's it.








 
 
 

Comments


bottom of page