domingo, 24 de enero de 2010

Retrieving Oracle patches with wget

Retrieving Oracle patches with wget

Update #1, 13-Nov-2009: While testing this patch download method in the wake of the recent My Oracle Support cutover, I noticed a new wrinkle. Instead of a successful patch download, I got the following message from wget:

Self-signed certificate encountered.
To connect to login.oracle.com insecurely, use `--no-check-certificate'.

After adding --no-check-certificate to the wget command, I was once again able to retrieve patches, but it took a bit longer than usual, as wget wandered through a tree of redirects. I've updated the code for the getOraPatch function accordingly.

Update #2, also 13-Nov-2009: A commenter on Chris Warticki's Oracle Support blog noted that the patch download page provided by the Flash version of My Oracle Support does not present a right-clickable Download button, which would seem to render the wget patch retreival method useless. Thankfully, there's a workaround: open a new window/tab in your browser, using an URL of the form https://updates.oracle.com/ARULink/PatchDetails/process_form?patch_num=nnnnnnn This will open a patch download page in a plain HTML, non-Flashy interface, and you should be all set to go!

No, no, this isn't a back door into the Metalink My Oracle Support patch repository. Don't get too excited. ;-)

While working from home this evening, I had to download some patches to a remote Linux system, and was struck, not for the the first time, by the inconvenience of it all. The usual options seem to be:

  1. Download the patches to a local machine and upload them to the remote system -- annoyingly manual at best, and downright gross when a VPN connection is involved.
  2. FTP from the remote system to updates.oracle.com. That's a tried-and true method, but still involves a lot of typing. Not anymore! This access option was disabled in November 2009, with the arrival of My Oracle Support.
  3. Start a VNC session on the remote system, launch a web browser, log in to Metalink My Oracle Support, and click the download button. Not a bad option...unless you can't use VNC for some reason, and are stuck with a command-line interface. Or if you're trying to navigate in that remote browser over a VPN connection. Not an exercise for impatient people.

When life gives you inconvenience, write a shell function!

At least, I think that's how the old saying goes. I created the following bash(1) function that uses wget to download a patch from updates.oracle.com, using the URL behind the Download button:

# Function to retreive patches from Metalink/My Oracle Support via wget
function getOraPatch {
[[ $mosUser ]] || read -p "Oracle Support Userid: " mosUser;
[[ $mosPass ]] || read -sp "Oracle Support Password: " mosPass;
fname=`echo $1 | awk -F"=" '{print $NF;}'`;
wget --no-check-certificate --http-user $mosUser --http-passwd $mosPass $1 -O $fname;
}

The above function prompts for the username and password that you use to access Metalink My Oracle Support. If the variables are already defined in your session, then it assumes you want to use the existing values and does not prompt you again. Then, the function parses the patch URL to find the patch's filename, and passes all four values (userid, password, URL, and filename) to wget.

Usage example

  1. Load the above function into your shell session, or copy and paste the code into your .bash_profile to have it loaded when you log in.
  2. Log in to Metalink My Oracle Support and locate the patch. Can't get around this step, but you can do it in a local browser, instead of dealing with a remote X session as described above in #3.
  3. Right-click on the Download button to copy the patch URL:
    Patch download window
  4. Invoke the function, enclosing the super-long patch URL in single quotes:
    oracle@testhost:/stage> getOraPatch 'really_long_patch_URL_copied_in_previous_step'
  5. Answer the prompts, and lean back and watch as wget retrieves your patch:
    Oracle Support Userid: your_MyOracleSupport_login_here
    Oracle Support Password: your_MyOracleSupport_password_here
    (some wget output snipped)
    HTTP request sent, awaiting response... 200 OK
    Length: 52,028 [application/zip]

    100%[====================================>] 52,028 --.--K/s

    22:27:24 (555.94 KB/s) - `pnnnnnnn_version_platform.zip' saved [52028/52028]