Hello everyone
While working on TUI for scripts, there there came the idea to' add a command' for dd too.
That was, after 'wrapping' tar and wget either, to display their growing size and return the exit code with a textual-visual-feedback to the user.
Now displaying the filesize of a tarball or a file that is downoaded during a loop is quite easy.
What i'd like to get is the value of how many times BS (as in bytesize) has been written.
So it would look similar to (the console output):
Linux : [ Text User Interface ] : tui-download & tui-tar - YouTube
At around 0:40 of the video.
The full script is:
Note that tui-printf & tui-status can be replaced by 'printf' or 'echo'
tui-indi prints on each call the following of its previous -/|\
source tui
loads in the configuration files/default variables not defined in this script.
#!/bin/sh
# Author: Simon A. Erat (sea)
# Contact: erat.simon@gmail.com
#
# Variable defaults
#
script_version=0.3
ME="$(basename $0)"
help_text="\r$ME ($script_version)
\rUsage: $ME SOURCE TARGET
\rWrites SOURCE to TARGET
\rRequires root rights.
\r"
source tui
FILE_CMD="$TUI_TEMP_DIR/bgjob"
SOURCE="$1"
TARGET="$2"
#
# Variable handling
#
if [[ "$1" = "-h" ]] || [[ -z $2 ]];then
echo -e "$help_text" && exit $RET_HELP;fi
#
# Display
#
CMD="dd if=$SOURCE of=$TARGET bs=$DD_BS status=none > /dev/zero"
echo "$CMD" > $FILE_CMD ; chmod +x $FILE_CMD ; $FILE_CMD &
sleep 0.3
while [[ ! "" = "$(ps|grep -v tui|grep dd)" ]]
do sleep 0.7
tui-printf "Writing $(basename $SOURCE) to $TARGET" " [ $(tui-indi) ]"
done
tui-status $? "Written $(basename $SOURCE) to $TARGET"
Which works like it should.
According to the manpage, one's supposed to get job's info by:
So i've changed accordingly:
(removed because outdated)
Problem now is:
# | Writing sea-AwesomeWM-F19.iso to /dev/sdb ) [ / ] | #63+0 records in
63+0 records out
264241152 bytes (264 MB) copied, 4.22988 s, 62.5 MB/s
# | Writing sea-AwesomeWM-F19.iso to /dev/sdb ) [ - ] | #65+0 records in
65+0 records out
272629760 bytes (273 MB) copied, 5.19806 s, 52.4 MB/s
# | Writing sea-AwesomeWM-F19.iso to /dev/sdb ) [ \ ] | #66+0 records in
66+0 records out
276824064 bytes (277 MB) copied, 6.16454 s, 44.9 MB/s
# | Writing sea-AwesomeWM-F19.iso to /dev/sdb ) [ | ] | #
^C130 ~ $
I hoped redirecting the stderr to a variable would keep DD quite...
How could i achieve this?
...
CMD="dd if=$SOURCE of=$TARGET bs=$DD_BS"
...
while [[ ! "" = "$(ps|grep -v tui|grep dd)" ]]
do sleep 0.7
pid=$(ps|grep -v tui|grep dd|awk '{print $1}')
kill -USR1 $pid 2&> $TUI_TEMP_FILE
tmp=$(grep "," $TUI_TEMP_FILE|awk '{print $3" "$4}')
tui-printf "Writing $(basename $SOURCE) to $TARGET $tmp)" " [ $(tui-indi) ]"
done
---------- Post updated at 16:39 ---------- Previous update was at 15:14 ----------
According to the manpages, this is supposed to work:
However, i have tried:
- kill -USR1 $pid 1&>2 > $TUI_TEMP_FILE
- kill -USR1 $pid 2&>1 > $TUI_TEMP_FILE
- kill -USR1 $pid > $TUI_TEMP_FILE > 2&>1
- CMD="dd if=$SOURCE of=$TARGET bs=$DD_BS > $TUI_TEMP_FILE > 2&>1" # status=none
In all caes $TUI_TEMP_FILE remained empty, while - if there were output - it was only shown to user but not written to tempfile.
It seems dd is either 'spamy' or dead-silent...
Any hints welcome. (or what am i understanding wrong?)