3

So I have a shell script that basicly backs up one server to another server. In the process I have to cp a very large directory (140GB) to another location, in the shell script I would love to have it run a real time stopwatch type counter starting from 0:00 as the files are copying.

Possible?

EDIT: This is not a progress bar idea :) Just a simple stopwatch timer so you can see how much time is elapsed, rather then the time until the pain is over :)

3

Just in case David Kings rsync solution doesn't work for you or you do want to do it in bash (why ever), this is how you could do it:

#!/bin/bash
your_command_to_execute &
myPid=$!
sleepTime=5
while kill -0 "$myPid" 2> /dev/null
do
    # Sleep for the defined time
    sleep $sleepTime
    # And print the time since the script started in seconds
    echo -en "Runtime $SECONDS\033[0K\r"
done

You might want to use something to format the time a little bit nicer.
Also currently the script prints the seconds since the script started, and not since the cp operation started (if you want to change this simple subtract the seconds before the loop from the current $SECONDS)

2

Would using rsync -av --progress instead of cp do what you want?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.