Frage
Ich fand den folgenden Bash-Skript, um Monitor cp Fortschritt.
#!/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
}
Ich verstehe nicht die „-ewrite“ Option für den Strace Befehl. Das nächste, was ich gefunden habe, ist die Manpage für strace das ist
-e write = Satz Führen Sie einen vollständigen hexadezimal und ASCII-Dump alles Daten zu Filedeskriptoren geschrieben im angegebenen Satz aufgeführt. Zum Beispiel alle Ausgabeaktivität sehen auf Datei-Deskriptoren 3 und 5 Verwendung -e write = 3,5. Beachten Sie, dass dies unabhängig von der normalen Verfolgung von die Schreib (2) -Systemaufruf welches durch die Option -e gesteuert trace = write.
Allerdings verstehe ich nicht, was die -ewrite Option der Fall ist.
Lösung
-ewrite bedeutet, dass nur der "write" Systemaufruf zurückverfolgt werden.
-e expr eine qualifizierende Ausdruck, modifiziert, welche Ereignisse zu verfolgen oder wie sie verfolgen. Das Format der Ausdruck ist:
[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.