Capturing yum progress bar percentage
Solution 1
The progress bars are written out only when the output is going to terminal. You may simulate that with using expect (with ExpectJ being Java implementation) but parsing application output (thing called screen scraping) can be very fragile method and would break when output changes, for example depending on width of output terminal, length of package names and perhaps other things.
Yum is written in python and is extensible with plugins so you may try to write a plugin to talk to your application and notify on the progress, but it does not look worth the trouble to me.
Here are the docs if you decided to go that way.
To simply wrap yum in an expect you can use something like:
#!/usr/bin/expect -f
set timeout 600
spawn yum -y install zsh-html
expect eof
After this you can catch output and see packages being downloaded there.
Solution 2
I don't think this behavior is a terminal vs file matter, to me it has to do with buffering.
From my experience, the unbuffer
command works pretty fine:
unbuffer yum install pkg_name > captured
and then you can follow the progress:
tail -f -n 0 captured
On CentOS 7, use yum provides '*/bin/unbuffer'
to find the package providing the unbuffer
command.
Related videos on Youtube
SSaikia_JtheRocker
Programming enthusiast. Current interest Java, Hadoop (MapReduce & Cluster configuration). Here to learn from you great people. I also like to play Guitar and Sing.
Updated on September 18, 2022Comments
-
SSaikia_JtheRocker over 1 year
I would like to know if it's possible to capture download progress i.e percentage download complete shown by 'yum' while it's downloading a package. Capture, in the sense, could be to a text file or programatically using JAVA, for an instance, if I run the yum installer from JAVA.
I've tried
yum install pkg_name > captured
, but it captures the standard output only without the progress information.I've also checked stderr, no result.
E.g.
Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package wget.i686 0:1.12-4.fc14 set to be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: wget i686 1.12-4.fc14 updates 481 k Transaction Summary ================================================================================ Install 1 Package(s) Total download size: 481 k Installed size: 1.8 M Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : wget-1.12-4.fc14.i686 1/1 Installed: Wget.i686 0:1.12-4.fc14 Complete!
Along with the above info, I'd also like to the capture the progress part i.e percentage complete that is shown below the 'Downloading Packages:' label while downloading.
I don't use Python scripts.
-
SSaikia_JtheRocker over 12 yearsThat was very useful. I don't have enough reputation to give you an up :(
-
Martian over 12 yearsLessons learned: never answer a question from someone with low reputation ;-) [Do not worry about that, glad to help!]
-
Halil Özgür about 12 years@JtheRocker I upvoted for you :) Just giving credit where it needs to be given...