Solved

How to display a progress bar of remote linux process

Posted on 2011-09-30
3
491 Views
Last Modified: 2012-05-12
I am looking for a way to generate a progress bar for a process executing on a remote linux machine (through ssh). The process on the remote machine is a g++ compilation of a big C++ project.

A lot of output text is produced by the compilation process. I imagine to generate the progress bar by displaying (in the shell on the local machine) a "#" each time a line starting with "Making install in" comes out from the compilation process on the remote machine (I know how many such lines it will be in total, so I know how long the progress bar will be).

The remote process is started from a python script on the local machine, and I have currently come so far:

cmd="ssh "+rhost+" \"cd "+r_build_dir+" ; make -j install | grep 'Making install in'\""
os.system(cmd)
# perhaps I could also have used: commands.getoutput(cmd) instead of os.system(cmd)

This kind of does what I want, but the whole point is lost because all the lines come out at once when the remote compilation process is done!, e.g.:

Making install in ProjectRoot
Making install in ProjectRoot/Project1
Making install in ProjectRoot/Project2
Making install in ProjectRoot/Project3

Of course the lines should be displayed one by one as the compilation progresses. Ideally I don't even want see those lines coming, but a growing progress bar.

The solution is probably related to flushing stdout and ssh. You experts probably have a "one-liner" to do the job!

Thanks!
0
Comment
Question by:Phazz
3 Comments
 
LVL 9

Expert Comment

by:parparov
ID: 36894867
You may want not to pipe the output into grep, but redirect it into the file, and fork a parallel process that would access the remote machine, read the redirected file and output progress as it goes.

0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 36900037
You probably want to use the subprocess module and popen to catch the output as it comes in.  The os.system is just going to execute the command.

import re
from subprocess import Popen,PIPE

lookfor = re.compile(r'Making install in')

rhost = "somehost"
cmd = "ssh "+rhost+" \"cd "+r_build_dir+" ; make -j install"

build = Popen(cmd, stdout=PIPE, shell=True, universal_newlines = True, bufsize=1024 )

count = 0
while build.poll() == None:
        line = build.stdout.readline(1024).strip()
        if (lookfor.match(line)):
                count = count + 1
                print "%04d" % count

Open in new window

0
 

Author Closing Comment

by:Phazz
ID: 36908296
Excellent, brilliant! Thanks a lot!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
python question 5 60
Auto channel for WiFi (Access Point) 3 51
a free alternative to cpanel? 1 39
AWS CLI issues with Tags 3 31
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now