|
From: | Chris Elvidge |
Subject: | Re: wait until the file is done |
Date: | Sun, 1 Nov 2020 13:27:29 +0000 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Lightning/5.4 |
On 01/11/2020 11:37 am, MN wrote:
Thank you Chris! I modifed the function as per your suggestion. I tried it and it worked well. How I should increase its verbosity? [ -e "$1" ] || echo 'No such file'; return 1 Is this any good? On 20-10-31 18:15:16, Chris Elvidge wrote:On 31/10/2020 04:13 pm, MN wrote:I thought I would make the function typo-proof. Is this how it should be done? waitfor() { oldsize=0 if [[ -e "$1" ]]; then #new lines while sleep 30; do size=$(wc -c < "$1") if ((size > oldsize)); then oldsize=$size SECONDS=0 continue fi if ((SECONDS > 600)); then break fi done else #new lines echo 'No such file' #new lines fi }waitfor() { # return error if $1 not exists [ -e "$1" ] || return 1 oldsize=0 size=$(wc -c <"$1") # check if size increased in last 30 seconds while ((size>oldsize)); do oldsize=$size sleep 30 size=$(wc -c <"$1") done } -- Chris Elvidge England
That would need {...} around the echo and return. Pehaps better would be [ -s "$1" ] || { echo "No file found/File not found"; return 1; }
-s : checks for file existing and containing something { ...; ...; } semicolons are needed inside curly braces For even more verbosity try a line likeecho -n "$size " or printf "%d " "$size" just before the oldsize=$size line (note the space inside the quotes).
-- Chris Elvidge England
[Prev in Thread] | Current Thread | [Next in Thread] |