Heyas
I'm reworking tui-dd atm, and having a similar issue with a 'weird formated tempfile'.
I've already applied what seemed to help from: This awk should work, shouldn't it? - Page 2
However, it is weird...
The mini-dd works as expected, where tui-dd with the same functions fails...
mini-dd.sh - output, as expected:
Bytes transfered:
Bytes transfered: 6459904
Bytes transfered: 12796416
Bytes transfered: 19112448
Bytes transfered: 25678336
mini-dd.sh - code
#!/bin/bash
#
# Variables
#
TMP="/tmp/dd.tmp~"
SOURCE="/home/sea/net/dls/parabola-2015.11.11-dual.iso"
TARGET="/dev/sdc"
GREP=\grep
AWK=\gawk
SED=\sed
LC_ALL=C
opts_passed="status=progress"
#
# Functions
#
transfered_bytes() { #
# Parses the tempfile and prints the bytes transfered
# tempfile is similar garabe/hexdump as a curl transfer rate
value="$(
$AWK -vRS=$'\r' \
'END{NR=1}END {print $1}' \
"$TMP" | tail -n1
)"
printf '%s' "$value" | $SED s,"[(|)]","",g
}
write_dd() { #
# Starts dd, prints the exit status
# syncs device if required
dd $opts_passed \
if="$SOURCE" \
of="$TARGET" \
2>"$TMP"
printf $? > "$TMP"
sync
}
#
# Action
#
>$TMP # Clear temp file
write_dd & # Start job in background
PID=$! # Get PID
while ps $PID 2>/dev/zero 1>/dev/zero
do # Request data & print it
echo "Bytes transfered: $(transfered_bytes)"
sleep 1
done
#
# Clear
#
LC_ALL=""
'Final script' - output
0 /home/sea/net/dls # /home/sea/prjs/tui/bin/tui-dd parabola-2015.11.11-dual.iso /dev/sdc
# | Starting job, please wait... [ ] | #
-- **** EMPTY $CUR **** --
# | DBG::( ,) -- Written /530 MB of parabola-2015.11.11-dual.iso to /dev/sdc [== ][ 1.79% ] | # -- **** EMPTY $CUR **** --
# | DBG::( ,) -- Written /530 MB of parabola-2015.11.11-dual.iso to /dev/sdc [== ][ 1.79% ] | # -- **** EMPTY $CUR **** --
# | DBG::( ,) -- Written /530 MB of parabola-2015.11.11-dual.iso to /dev/sdc [== ][ 1.79% ] | # -- **** EMPTY $CUR **** --
# | DBG::( ,) -- Written /530 MB of parabola-2015.11.11-dual.iso to /dev/sdc [== ][ 1.79% ] | #^C
'Final script' - changed code
while [ ! "" = "$(ps|$GREP -v tui|$GREP dd|$AWK '{print $1}')" ]
sleep 0.7
do
# Variables
MB="$(transfered_mb)" # Get data from tempfile, slightly modified
CUR="$(transfered_bytes)" # Get data from tempfile, the same in both scripts
[ -z "$(echo $CUR)" ] && \
echo " -- **** EMPTY \$CUR **** -- " && \
hexdump -CL "$TMP"
# Prepare displayed string to user
#TXT="$(eval_gettext 'Written $MB/$MAX_MB of $SRC to $TARGET')"
TXT="DBG::($MB,$CUR) -- Written $MB/$MAX_MB of $SRC to $TARGET"
# Visual output
tui-progress -lbm ${MAX:-10} -c ${CUR:-1} "$TXT"
done
Debug output:
+ SOURCE=parabola-2015.11.11-dual.iso
+ TARGET=/dev/sdc
+ TMP=/root/.cache/tui.tmp~
+ MAX=0
+ SRC=parabola-2015.11.11-dual.iso
++ eval_gettext 'Writing $SRC to $TARGET...'
++ gettext 'Writing $SRC to $TARGET...'
+++ envsubst --variables 'Writing $SRC to $TARGET...'
++ export PATH SRC TARGET
++ envsubst 'Writing $SRC to $TARGET...'
+ TR_MSG_STRING_WORK='Writing parabola-2015.11.11-dual.iso to /dev/sdc...'
++ eval_gettext 'Written $SRC to $TARGET'
++ gettext 'Written $SRC to $TARGET'
+++ envsubst --variables 'Written $SRC to $TARGET'
++ export PATH SRC TARGET
++ envsubst 'Written $SRC to $TARGET'
+ TR_MSG_STRING_DONE='Written parabola-2015.11.11-dual.iso to /dev/sdc'
++ eval_gettext 'Could not get type of "$SOURCE"!'
++ gettext 'Could not get type of "$SOURCE"!'
+++ envsubst --variables 'Could not get type of "$SOURCE"!'
++ export PATH SOURCE
++ envsubst 'Could not get type of "$SOURCE"!'
+ TR_MSG_WRONG_TYPE='Could not get type of "parabola-2015.11.11-dual.iso"!'
++ gettext 'Starting job, please wait...'
+ TR_MSG_STARTING='Starting job, please wait...'
+ export LC_ALL=C
+ LC_ALL=C
+ '[' -f /root/.cache/tui.tmp~ ']'
+ '[' -z ' ' ']'
+ echo 'status=progress '
+ grep -q bs=
+ opts_passed+=' bs=4M'
+ '[' /dev = /dev ']'
+ '[' 0 -ne 0 ']'
+ tui-printline -rS 2 'Starting job, please wait...'
+ PID=27875g job, please wait... [ ] | #
+ write_dd
+ dd status=progress bs=4M if=parabola-2015.11.11-dual.iso of=/dev/sdc
++ get_size parabola-2015.11.11-dual.iso
++ '[' -z parabola-2015.11.11-dual.iso ']'
++ item=parabola-2015.11.11-dual.iso
++ output=
++ '[' -b parabola-2015.11.11-dual.iso ']'
++ '[' -d parabola-2015.11.11-dual.iso ']'
++ '[' -f parabola-2015.11.11-dual.iso ']'
+++ of_file parabola-2015.11.11-dual.iso
+++ ls -l parabola-2015.11.11-dual.iso
+++ gawk '{print $5}'
++ output=555745280
++ echo 555745280
++ return 0
+ MAX=555745280
+ '[' -z 555745280 ']'
++ bytes2mb 555745280
++ echo 555745280
++ gawk '{print int ($1 / 1024 / 1024),"MB"}'
+ MAX_MB='530 MB'
++ ps
++ grep -v tui
++ grep dd
++ gawk '{print $1}'
+ '[' '!' '' = '27497
27877' ']'
+ sleep 0.7
++ transfered_mb
+++ gawk $'-vRS=\r' 'END{NR=1}END {print $3,$4}' /root/.cache/tui.tmp~
+++ tail -n1
++ value=' '
++ printf %s ' '
++ sed 's,[(|)],,g'
+ MB=' '
++ transfered_bytes
+++ gawk $'-vRS=\r' 'END{NR=1}END {print $1}' /root/.cache/tui.tmp~
+++ tail -n1
++ value=
++ printf %s ''
++ sed 's,[(|)],,g'
+ CUR=
++ echo
+ '[' -z '' ']'
+ echo ' -- **** EMPTY $CUR **** -- '
-- **** EMPTY $CUR **** --
+ hexdump -CL /root/.cache/tui.tmp~
+ TXT='DBG::( ,) -- Written /530 MB of parabola-2015.11.11-dual.iso to /dev/sdc'
+ set -x
+ tui-progress -lbm 555745280 -c 1 'DBG::( ,) -- Written /530 MB of parabola-2015.11.11-dual.iso to /dev/sdc'
# | DBG::( ,) -- Written /530 MB of parabola-2015.11.11-dual.iso to /dev/sdc [== ][ 1.79% ] | #+ echo
Debug output of mini-dd
0 /home/sea/net/dls # sh -x /home/sea/prjs/tui/bin/mini-dd.sh
+ TMP=/tmp/dd.tmp~
+ SOURCE=/home/sea/net/dls/parabola-2015.11.11-dual.iso
+ TARGET=/dev/sdc
+ GREP=grep
+ AWK=gawk
+ SED=sed
+ LC_ALL=C
+ opts_passed=status=progress
+ PID=30287
+ ps 30287
+ write_dd
+ dd status=progress if=/home/sea/net/dls/parabola-2015.11.11-dual.iso of=/dev/sdc
++ transfered_bytes
+++ gawk $'-vRS=\r' 'END{NR=1}END {print $1}' /tmp/dd.tmp~
+++ tail -n1
++ value=
++ printf %s ''
++ sed 's,[(|)],,g'
+ echo 'Bytes transfered: '
Bytes transfered:
+ hexdump -CL /tmp/dd.tmp~
+ sleep 1
+ ps 30287
++ transfered_bytes
+++ gawk $'-vRS=\r' 'END{NR=1}END {print $1}' /tmp/dd.tmp~
+++ tail -n1
++ value=6493696
++ printf %s 6493696
++ sed 's,[(|)],,g'
+ echo 'Bytes transfered: 6493696'
Bytes transfered: 6493696
+ hexdump -CL /tmp/dd.tmp~
00000000 0d 36 34 39 33 36 39 36 20 42 79 74 65 73 20 28 |.6493696 Bytes (|
00000010 36 2e 35 20 4d 42 29 20 6b 6f 70 69 65 72 74 2c |6.5 MB) kopiert,|
00000020 20 31 2e 30 30 30 30 30 30 20 73 2c 20 36 2e 35 | 1.000000 s, 6.5|
00000030 20 4d 42 2f 73 | MB/s|
00000035
+ sleep 1
+ ps 30287
++ transfered_bytes
+++ gawk $'-vRS=\r' 'END{NR=1}END {print $1}' /tmp/dd.tmp~
+++ tail -n1
++ value=12984832
++ printf %s 12984832
++ sed 's,[(|)],,g'
+ echo 'Bytes transfered: 12984832'
Bytes transfered: 12984832
+ hexdump -CL /tmp/dd.tmp~
00000000 0d 36 34 39 33 36 39 36 20 42 79 74 65 73 20 28 |.6493696 Bytes (|
00000010 36 2e 35 20 4d 42 29 20 6b 6f 70 69 65 72 74 2c |6.5 MB) kopiert,|
00000020 20 31 2e 30 30 30 30 30 30 20 73 2c 20 36 2e 35 | 1.000000 s, 6.5|
00000030 20 4d 42 2f 73 0d 31 32 39 38 34 38 33 32 20 42 | MB/s.12984832 B|
00000040 79 74 65 73 20 28 31 33 20 4d 42 29 20 6b 6f 70 |ytes (13 MB) kop|
00000050 69 65 72 74 2c 20 32 2e 30 30 30 36 30 33 20 73 |iert, 2.000603 s|
00000060 2c 20 36 2e 35 20 4d 42 2f 73 |, 6.5 MB/s|
0000006a
+ sleep 1
<....>
+ hexdump -CL /tmp/dd.tmp~
00000000 0d 36 35 35 30 30 31 36 20 42 79 74 65 73 20 28 |.6550016 Bytes (|
00000010 36 2e 36 20 4d 42 29 20 6b 6f 70 69 65 72 74 2c |6.6 MB) kopiert,|
00000020 20 31 2e 30 30 30 34 31 32 20 73 2c 20 36 2e 35 | 1.000412 s, 6.5|
00000030 20 4d 42 2f 73 0d 31 32 39 33 35 36 38 30 20 42 | MB/s.12935680 B|
00000040 79 74 65 73 20 28 31 33 20 4d 42 29 20 6b 6f 70 |ytes (13 MB) kop|
00000050 69 65 72 74 2c 20 32 2e 30 30 30 34 34 31 20 73 |iert, 2.000441 s|
00000060 2c 20 36 2e 35 20 4d 42 2f 73 0d 31 39 32 38 34 |, 6.5 MB/s.19284|
00000070 34 38 30 20 42 79 74 65 73 20 28 31 39 20 4d 42 |480 Bytes (19 MB|
00000080 29 20 6b 6f 70 69 65 72 74 2c 20 33 2e 30 30 30 |) kopiert, 3.000|
00000090 37 38 37 20 73 2c 20 36 2e 34 20 4d 42 2f 73 0d |787 s, 6.4 MB/s.|
000000a0 32 35 36 38 32 34 33 32 20 42 79 74 65 73 20 28 |25682432 Bytes (|
000000b0 32 36 20 4d 42 29 20 6b 6f 70 69 65 72 74 2c 20 |26 MB) kopiert, |
000000c0 34 2e 30 30 31 31 33 37 20 73 2c 20 36 2e 34 20 |4.001137 s, 6.4 |
000000d0 4d 42 2f 73 0d 33 31 39 32 30 36 34 30 20 42 79 |MB/s.31920640 By|
000000e0 74 65 73 20 28 33 32 20 4d 42 29 20 6b 6f 70 69 |tes (32 MB) kopi|
000000f0 65 72 74 2c 20 35 2e 30 30 31 32 39 39 20 73 2c |ert, 5.001299 s,|
00000100 20 36 2e 34 20 4d 42 2f 73 0d 33 38 32 36 35 33 | 6.4 MB/s.382653|
00000110 34 34 20 42 79 74 65 73 20 28 33 38 20 4d 42 29 |44 Bytes (38 MB)|
00000120 20 6b 6f 70 69 65 72 74 2c 20 36 2e 30 30 31 38 | kopiert, 6.0018|
00000130 31 30 20 73 2c 20 36 2e 34 20 4d 42 2f 73 0d 34 |10 s, 6.4 MB/s.4|
00000140 34 36 39 36 30 36 34 20 42 79 74 65 73 20 28 34 |4696064 Bytes (4|
00000150 35 20 4d 42 29 20 6b 6f 70 69 65 72 74 2c 20 37 |5 MB) kopiert, 7|
00000160 2e 30 30 31 38 32 35 20 73 2c 20 36 2e 34 20 4d |.001825 s, 6.4 M|
00000170 42 2f 73 0d 35 31 32 31 32 38 30 30 20 42 79 74 |B/s.51212800 Byt|
00000180 65 73 20 28 35 31 20 4d 42 29 20 6b 6f 70 69 65 |es (51 MB) kopie|
00000190 72 74 2c 20 38 2e 30 30 32 31 31 35 20 73 2c 20 |rt, 8.002115 s, |
000001a0 36 2e 34 20 4d 42 2f 73 0d 35 37 37 34 35 39 32 |6.4 MB/s.5774592|
000001b0 30 20 42 79 74 65 73 20 28 35 38 20 4d 42 29 20 |0 Bytes (58 MB) |
000001c0 6b 6f 70 69 65 72 74 2c 20 39 2e 30 30 32 32 34 |kopiert, 9.00224|
000001d0 37 20 73 2c 20 36 2e 34 20 4d 42 2f 73 0d 36 34 |7 s, 6.4 MB/s.64|
000001e0 32 33 38 30 38 30 20 42 79 74 65 73 20 28 36 34 |238080 Bytes (64|
000001f0 20 4d 42 29 20 6b 6f 70 69 65 72 74 2c 20 31 30 | MB) kopiert, 10|
00000200 2e 30 30 32 35 38 31 20 73 2c 20 36 2e 34 20 4d |.002581 s, 6.4 M|
00000210 42 2f 73 0d 36 39 32 30 32 34 33 32 20 42 79 74 |B/s.69202432 Byt|
00000220 65 73 20 28 36 39 20 4d 42 29 20 6b 6f 70 69 65 |es (69 MB) kopie|
00000230 72 74 2c 20 31 31 2e 30 32 31 31 34 38 20 73 2c |rt, 11.021148 s,|
00000240 20 36 2e 33 20 4d 42 2f 73 0d 37 34 30 35 32 30 | 6.3 MB/s.740520|
00000250 39 36 20 42 79 74 65 73 20 28 37 34 20 4d 42 29 |96 Bytes (74 MB)|
00000260 20 6b 6f 70 69 65 72 74 2c 20 31 32 2e 30 32 31 | kopiert, 12.021|
00000270 35 32 33 20 73 2c 20 36 2e 32 20 4d 42 2f 73 0d |523 s, 6.2 MB/s.|
00000280 37 38 32 34 34 38 36 34 20 42 79 74 65 73 20 28 |78244864 Bytes (|
00000290 37 38 20 4d 42 29 20 6b 6f 70 69 65 72 74 2c 20 |78 MB) kopiert, |
000002a0 31 33 2e 30 32 31 35 32 34 20 73 2c 20 36 2e 30 |13.021524 s, 6.0|
000002b0 20 4d 42 2f 73 0d 38 33 34 34 30 31 32 38 20 42 | MB/s.83440128 B|
000002c0 79 74 65 73 20 28 38 33 20 4d 42 29 20 6b 6f 70 |ytes (83 MB) kop|
000002d0 69 65 72 74 2c 20 31 34 2e 30 32 31 37 35 31 20 |iert, 14.021751 |
000002e0 73 2c 20 36 2e 30 20 4d 42 2f 73 0d 38 38 33 37 |s, 6.0 MB/s.8837|
000002f0 39 39 30 34 20 42 79 74 65 73 20 28 38 38 20 4d |9904 Bytes (88 M|
00000300 42 29 20 6b 6f 70 69 65 72 74 2c 20 31 35 2e 30 |B) kopiert, 15.0|
00000310 32 32 31 34 31 20 73 2c 20 35 2e 39 20 4d 42 2f |22141 s, 5.9 MB/|
00000320 73 0d 39 33 32 35 38 32 34 30 20 42 79 74 65 73 |s.93258240 Bytes|
00000330 20 28 39 33 20 4d 42 29 20 6b 6f 70 69 65 72 74 | (93 MB) kopiert|
00000340 2c 20 31 36 2e 30 32 32 37 33 34 20 73 2c 20 35 |, 16.022734 s, 5|
00000350 2e 38 20 4d 42 2f 73 0d 39 38 33 37 38 32 34 30 |.8 MB/s.98378240|
00000360 20 42 79 74 65 73 20 28 39 38 20 4d 42 29 20 6b | Bytes (98 MB) k|
00000370 6f 70 69 65 72 74 2c 20 31 37 2e 30 35 31 31 35 |opiert, 17.05115|
00000380 36 20 73 2c 20 35 2e 38 20 4d 42 2f 73 |6 s, 5.8 MB/s|
0000038d
+ sleep 1
^C
What confuses me is that i copied the 2 functions from one file to the other, but having different behaviour.
They're even called identical.
Also, the script that works, keeps parsing NR=1, not any 'high' number, as with the past issue.
Any ideas?
Thank you in advance.