Wednesday, 8 February 2017

Script to download patch directly to linux server

Below is the generic script to download patch from metalink....

[mxm510@acop1 DBA]$ cat patch_download.sh

clear
export http_proxy='http://172.18.100.15:18717'
export https_proxy='http://172.18.100.15:18717'

for var in "$@" ; do eval "export p_${var}"; done

if [ -z ${p_patch_loc} ]
then
echo -e "Patch Files will be downloaded to ${HOME} ...\n\n"
p_patch_loc=$HOME
fi

if [ -z ${p_patch} ]
then
echo -e "Patches not specified. Please enter list of comma seperated patches ... \n\n"
read -p "Patch List : " p_patch
fi


if [ -z ${p_patch} ]
then
exit
fi



save_wget="--secure-protocol=TLSv1 --save-cookies=$HOME/cookie.txt --keep-session-cookies --no-check-certificate"
load_wget="--secure-protocol=TLSv1 --no-check-certificate --load-cookies=$HOME/cookie.txt"

echo -e "\n\nEnter Patch Type. For E-biz Type => appl , For Database Type => db ... \n\n"
read -p "Patch Type : " patch_type
echo -e "\n\n"

if [ $(echo ${patch_type} | tr '[:lower:]' '[:upper:]') = 'APPL' ]
then
v_r12_b_patch='.*B_R12.*'
fi

patch_url=$HOME/patch_url.lst
patch_url_tmp=$HOME/patch_url_temp.lst

echo -e "Enter Oracle Support Credentials\n\n"
read -p "Enter Oracle Support Userid: " support_user
read -sp "Enter Oracle Support Password: " support_password
echo "user=${support_user}" > $HOME/.wgetrc
echo "password=${support_password}" >> $HOME/.wgetrc
chmod 600 $HOME/.wgetrc

wget ${save_wget} "https://updates.oracle.com/Orion/SimpleSearch/switch_to_saved_searches" -O $HOME/outfile.txt -o $HOME/logfile.txt --no-verbose

wget_result=$?

if [ ${wget_result} -ne 0 ]
then
cat $HOME/logfile.txt
exit
fi

echo -e "\n\nGetting List of Platform and Languages ..."
wget ${load_wget} "https://updates.oracle.com/Orion/SavedSearches/switch_to_simple" -O $HOME/outfile.txt -q

clear

grep -A999 "<select name=plat_lang" $HOME/outfile.txt | grep "^<option" | grep -v "\-\-\-" | awk -F "[\">]" '{print $2" - "$4}'
#grep -A999 "<select name=plat_lang" $HOME/outfile.txt | grep "^<option" | awk -F "[\">]" '{print $2" - "$4}'

echo -e "\n\n"

read -p "Enter Comma seperated list of Platform and Languages: " plat_lang_code

clear

echo "Downloading patches to - ${p_patch_loc} ..."

for patch_number in $(echo $p_patch | sed "s/,/ /g" | xargs -n 1 echo )
do

> $patch_url_tmp

for v_plat_land_code in $(echo $plat_lang_code | sed "s/,/ /g" | xargs -n 1 echo )
do
#echo ${v_plat_land_code}
echo -e "\n\n"
wget ${load_wget}  "https://updates.oracle.com/Orion/SimpleSearch/process_form?search_type=patch&patch_number=${patch_number}&plat_lang=${v_plat_land_code}" -O ${patch_url_tmp} -q
grep "Download/process_form" ${patch_url_tmp} | egrep "${v_r12_b_patch}" | sed 's/ //g' | sed "s/.*href=\"//g" | sed "s/\".*//g" > ${patch_url}
#cat $patch_url
cat ${patch_url} | while read line
do
file_name=`echo ${line} | awk -F= '{print $NF}' | sed "s/[?&]//g"`
#echo ${file_name}
echo "Downloading Patch File - ${file_name} ..."
wget ${load_wget} "${line}" -O "${p_patch_loc}/${file_name}" -q
echo "Checking integrity of Compressed Files - ${file_name} ..."
unzip -qt ${p_patch_loc}/${file_name}
done
done
done

rm ${patch_url}
rm ${patch_url_tmp}
rm $HOME/outfile.txt $HOME/cookie.txt $HOME/logfile.txt
echo -e "\n\n"

echo -e "All Patch Files Downloaded to location - ${p_patch_loc} ...\n\n"
ls -l ${p_patch_loc}
echo -e "\n\n"
> $HOME/.wgetrc

No comments:

Post a Comment