0

I found the following bash script in order to monitor cp progress.

#!/bin/sh
cp_p()
{
   strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
      | awk '{
        count += $NF
            if (count % 10 == 0) {
               percent = count / total_size * 100
               printf "%3d%% [", percent
               for (i=0;i<=percent;i++)
                  printf "="
               printf ">"
               for (i=percent;i<100;i++)
                  printf " "
               printf "]\r"
            }
         }
         END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
}

I don't understand the "-ewrite" option for the strace command. The closest thing I've found is the man page for strace which is

-e write=set Perform a full hexadecimal and ASCII dump of all the data written to file descriptors listed in the specified set. For example, to see all output activity on file descriptors 3 and 5 use -e write=3,5. Note that this is independent from the normal tracing of the write(2) system call which is controlled by the option -e trace=write.

However I don't understand what the -ewrite option does.

Albinoswordfish
  • 1,949
  • 7
  • 34
  • 50
  • Did you get the code from here @ http://chris-lamb.co.uk/2008/01/24/can-you-get-cp-to-give-a-progress-bar-like-wget/ and have you tried the alternative technique using secure copy **scp**? BTW You should have specified the source of the script in where you got it from... – t0mm13b Aug 23 '10 at 14:01
  • Point of detail: `strace` is primarily Linux, though it may be available on some other platforms too. Solaris uses `truss` or the Dtrace system, for instance; I can never remember what the equivalents on HP-UX and AIX are. – Jonathan Leffler Aug 23 '10 at 14:05
  • @tommieb75 yes I got the script from there. – Albinoswordfish Aug 23 '10 at 15:08

1 Answers1

4

-ewrite means that only the "write" system call will be traced.

-e expr A qualifying expression which modifies which events to trace or how to trace them. The format of the expression is:

                     [qualifier=][!]value1[,value2]...

          where qualifier is one of trace,  abbrev,  verbose,
          raw,  signal,  read, or write and value is a quali-
          fier-dependent symbol or number.  The default qual-
          ifier  is trace.  Using an exclamation mark negates
          the set of values.  For example, -eopen means  lit-
          erally -e trace=open which in turn means trace only
          the open system call.  By  contrast,  -etrace=!open
          means  to  trace every system call except open.  In
          addition, the special values all and none have  the
          obvious meanings.

          Note that some shells use the exclamation point for
          history expansion even inside quoted arguments.  If
          so,  you  must  escape the exclamation point with a
          backslash.
joast
  • 3,048
  • 2
  • 24
  • 16