LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need a script that does the following: (https://www.linuxquestions.org/questions/programming-9/need-a-script-that-does-the-following-606291/)

hackhound 12-12-2007 09:19 AM

Need a script that does the following:
 
Greetings,
I cannot get 'yum update' on a CentOS 5 box to work through our proxy server at work, and am now looking for a workaround. I am thinking that a script (bash, perl, etc) to do:

1. Take the output of 'yum check-update' and parse out everything but the package name.
2. Take the list of packages and retrieve them to a local directory with wget.
3. Update the box with 'yum localinstall'
4. Delete the updates after successful install.

I am working on a script, but thought would check here in case someone has done this already, or can bang something together quicker than I can.

Thanks,
Hackhound

unSpawn 12-12-2007 12:27 PM

Quote:

Originally Posted by hackhound (Post 2988313)
I cannot get 'yum update' on a CentOS 5 box to work through our proxy server

Why doesn't it work? What did you try? What where the (exact!) errors shown? And if it's using NTLM auth you could try http://ntlmaps.sourceforge.net/.


Quote:

Originally Posted by hackhound (Post 2988313)
with wget

If yum/apt/autoupdate/whatever else doesn't work why should wget work?


Quote:

Originally Posted by hackhound (Post 2988313)
I am working on a script

Awww, just post what you got.

hackhound 12-12-2007 03:26 PM

Quote:

Originally Posted by unSpawn (Post 2988521)
Why doesn't it work? What did you try? What where the (exact!) errors shown? And if it's using NTLM auth you could try http://ntlmaps.sourceforge.net/.

I don't want to get into alot of detail, because I have already beat this to death trying to get yum update to work. I have my env proxy variable set correctly, but when I execute yum update <packagename> I get:

[Errno -1] Header is not complete.

Quote:

Originally Posted by unSpawn (Post 2988521)
If yum/apt/autoupdate/whatever else doesn't work why should wget work?

My research of this error seems to indicate the problem lies with the proxy server not being able to handle the yum update request, which I have no control over. I tested wget, and it works fine.

Quote:

Originally Posted by unSpawn (Post 2988521)
Awww, just post what you got.

OK. Here is what I have so far. It's not pretty because I am taking this in a 'step by step' approach. Basically, what I have so far grabs a list or programs needing to be updated, strips off the status messages on the top 5 lines, grabs just the first column, and then reads each packagename and outputs it to the screen.

#!/bin/bash
cd yum-updates
yum check-update > update.log
sed '1,5d' update.log > yum1.log
awk '{print $1}' yum1.log > yum2.log
for i in $( cat yum2.log ); do
echo $i
done

Next steps would be to replace the 'echo $i' with the wget command, then run yum localinstall, then delete the file.

Like I said, not the nicest looking code, but I'm not an expert, and what I have so far is working.

Hackhound

unSpawn 12-12-2007 04:03 PM

Quote:

Originally Posted by hackhound (Post 2988656)
[Errno -1] Header is not complete.

Could be the proxy byte-range thingie.


Quote:

Originally Posted by hackhound (Post 2988656)
I tested wget, and it works fine.

If you don't mind me asking, did you try Yum with PGP sigs off and ftp or https style URI's by any chance?

hackhound 12-12-2007 04:13 PM

Quote:

Originally Posted by unSpawn (Post 2988686)
Could be the proxy byte-range thingie.

Could be. It's been a couple months since I investigated.

Quote:

Originally Posted by unSpawn (Post 2988686)
If you don't mind me asking, did you try Yum with PGP sigs off and ftp or https style URI's by any chance?

Can you elaborate on what I should be trying? I am rather sure that I am not using PSP sigs.

unSpawn 12-12-2007 04:38 PM

Hmm. There apparently are no mirrors providing HTTPS but definately Rsync and FTP. Tried using "ftp://mirror.pacific.net.au/linux/fedora/linux" instead of "http://mirror.pacific.net.au/linux/fedora/linux" style URI's in your .repo file?

hackhound 12-13-2007 08:39 AM

Quote:

Originally Posted by unSpawn (Post 2988723)
Hmm. There apparently are no mirrors providing HTTPS but definately Rsync and FTP. Tried using "ftp://mirror.pacific.net.au/linux/fedora/linux" instead of "http://mirror.pacific.net.au/linux/fedora/linux" style URI's in your .repo file?

Well, I tried that, and now it gives me the following:

Could not retrieve mirrorlist ftp://mirrorlist.centos.org/?release...h=i386&repo=os error was
[Errno 14] HTTP Error 502: Bad Gateway
Error: Cannot find a valid baseurl for repo: base

I don't have any problem getting the mirrorlist, the problem occurs when yum tries to grab a package from one of the sites in the mirrorlist.

Hackhound

unSpawn 12-13-2007 11:55 AM

Quote:

Originally Posted by hackhound (Post 2989396)
Error: Cannot find a valid baseurl for repo: base

See http://www.linuxquestions.org/questi...o-core-469993/ or http://www.linuxquestions.org/questi...r-repo-478600/ ?

hackhound 12-13-2007 12:28 PM

Uncommenting the baseurl line in yum.repos.d and then running yum udpate gives me the same "[Errno -1] Header is not complete." error.

unSpawn 12-14-2007 02:35 AM

I don't know what you're doing but "ftp://mirrorlist.centos.org/?release=5&arch=i386&repo=os" does not exist. Next to that I think help should be a two-way street and since you haven't exactly been forthcoming with details. Here's a script: remember YMMV(VM).
Code:

#!/bin/sh -
# Set debug and error mode when testing:
set -xe
# Make it a temp dir?
mkdir /tmp/yum-updates
cd /tmp/yum-updates
# Get list (your command, don't know if it works).
PKGS=$(yum check-update 2>/dev/null| sed '1,5d' | awk '{print $1}')
# Get packages. Replace basurl with the basurl of the repo.
for PKG in $PKGS; do wget "${baseurl}/$PKG" -P /tmp/yum-updates; done
# Install and only delete packages on success.
yum localinstall /tmp/yum-updates/*.rpm && \
rm -rf /tmp/yum-updates/*.rpm
exit 0


hackhound 12-14-2007 10:27 AM

Quote:

Originally Posted by unSpawn (Post 2990250)
I don't know what you're doing but "ftp://mirrorlist.centos.org/?release=5&arch=i386&repo=os" does not exist.

Correct. I did a global replace of http: with ftp: in yum.repos.d, which caused the mirrorlist url to be changed as well. I caught the mistake and changed it back to http:

Quote:

Originally Posted by unSpawn (Post 2990250)
Next to that I think help should be a two-way street and since you haven't exactly been forthcoming with details.

I do not know how I could be more forthcoming. I have tried everything you suggested and reported back my results. As you may recall, I never asked for help with getting yum to work, as I have beat this to death already without ever finding a solution. All I wanted was a script to give me a workaround, which I see that you have provided below.

Quote:

Originally Posted by unSpawn (Post 2990250)
Here's a script: remember YMMV(VM).
Code:

#!/bin/sh -
# Set debug and error mode when testing:
set -xe
# Make it a temp dir?
mkdir /tmp/yum-updates
cd /tmp/yum-updates
# Get list (your command, don't know if it works).
PKGS=$(yum check-update 2>/dev/null| sed '1,5d' | awk '{print $1}')
# Get packages. Replace basurl with the basurl of the repo.
for PKG in $PKGS; do wget "${baseurl}/$PKG" -P /tmp/yum-updates; done
# Install and only delete packages on success.
yum localinstall /tmp/yum-updates/*.rpm && \
rm -rf /tmp/yum-updates/*.rpm
exit 0


Thank You for the help.

unSpawn 12-14-2007 11:51 AM

NP, you're welcome. If you ever find a fix though I'd appreciate you posting a follow-up.


All times are GMT -5. The time now is 10:07 AM.