I know what I am about to say is an absolutely ugly hack, but...
If you cannot install non-standard software (example: customer owner, company operated RHEL boxes) you can get an idea of the current progress of cp/tar and similar programs by inspecting file-descriptor files in /proc.
Assuming that you have a process (like cp) with pid 1234, then in /proc/1234/fd you will find files with a number (corresponding to the file descriptor number in the context of the process) that are either symbolic links to the actual file or to socket connection (or other data structures). Let's assume that source file has fd 3 (you get this information via ls -l /proc/1234/fd )
Then, after you can cat /proc/1234/fdinfo/3 and look at the pos value: that's the position of the cursor in the file.
It's ugly and unpractical, but it should work on every Linux systems featuring basic tools.
#!/bin/sh
for pid in $@; do
cd /proc/"$pid"/fd || continue
for fd in *; do
file=$(readlink "$fd");
if [ ! -z "$file" ]; then
size=$( (du -b "$file" 2>/dev/null || echo 0) | awk '{print $1}')
if [ "$size" = "0" ]; then
continue
fi
pos=$(< ../fdinfo/"$fd" grep -F 'pos:' | grep -oP '\d+')
percent=$(echo "100*${pos}/${size}" | bc -l | xargs printf "%2.2f")
echo "${file}: ${percent}% (${pos}/${size})"
fi
done
done
This is what I call a "22/7" solution. Close enough to be useful but you'd never use it formally. This is really great to have in my back pocket the next time a long running copy process feels hanged (often via. Ansible) and I just want a sense of, "okay are we minutes, hours, or days away from being done?"
Some GNU utils use USR1 instead. It's not ideal, but it gets the job done.
I'd also like to map ^T to `kill -USR1 <pid>` on my machines, but didn't research it much.
> Sending an ‘INFO’ signal (or ‘USR1’ signal where that is unavailable) to a running dd process makes it print I/O statistics to standard error and then resume copying. [0]
-d PID[:FD], --watchfd PID[:FD]
Instead of transferring data, watch file descriptor FD of process PID,
and show its progress. The pv process will exit when FD either changes
to a different file, changes read/write mode, or is closed; other data
transfer modifiers - and remote control - may not be used with this
option.
If only a PID is specified, then that process will be watched, and all
regular files and block devices it opens will be shown with a progress
bar. The pv process will exit when process PID exits.
I always use pv when I want to monitor a long running operation, mainly because it shows the rate of progress as well as the ETA for the operation (of course, this is an estimate, but it's still useful).
'man pv' is a short read and is something anyone who want to monitor such things should read.
This is my super-simple progress indicator, called dots. I wrote it at least 12 years ago when I was on a slow terminal and wanted to know unpacking a tarball was still progressing (the verbose output would have taken too much bandwidth!). Now I copy it onto every new system I use.
It prints one period (.) for every 1000 lines of text piped into it. It just shows that there is still activity, not progress, but often this is enough.
A typical usage is:
tar xvfz some_huge_tarball.tar.gz | dots
It defaults to one dot per 1000 lines, but the first argument can be a number to specify another interval.
I had recently written a Python program (called watch.py) somewhat like the GNU watch [1] command (which user kjeetgill mentioned in another comment here).
zooming out, progress in the cloud is something that should be easier
plenty of our headless jobs know exactly where they are and how big the job is. There should be a standard dash for getting this.
even things like hadoop & luigi that have dashboards built in aren't great at progress & ETA
we should surface & store stats from any long-running loop. Further benefit that you can use prev runtime to properly schedule the next run (or run more sophisticated feedback & alerting).
If you cannot install non-standard software (example: customer owner, company operated RHEL boxes) you can get an idea of the current progress of cp/tar and similar programs by inspecting file-descriptor files in /proc.
Assuming that you have a process (like cp) with pid 1234, then in /proc/1234/fd you will find files with a number (corresponding to the file descriptor number in the context of the process) that are either symbolic links to the actual file or to socket connection (or other data structures). Let's assume that source file has fd 3 (you get this information via ls -l /proc/1234/fd )
Then, after you can cat /proc/1234/fdinfo/3 and look at the pos value: that's the position of the cursor in the file.
It's ugly and unpractical, but it should work on every Linux systems featuring basic tools.