On Sun, Jan 25, 2026 at 11:54:37AM -0700, [email protected] wrote: > Hello again, > > >From a private message, > > I modified your script slightly and it works for me. > > Thanks. > > The drive isn't formatted and has a UUID such as > 2026-01-19-03-28-45-00. Shorter than a UUID for a file system. > > After reading the reply I noticed that the UUID had changed. It's > revised periodically. After writing? Elapsed time is involved? I > don't understand in detail. > > UUID isn't a time-invariant identity for the drive. Two external > drives here are the same model. Serial number might identify. > > Revised the code listed yesterday. Now similar to this.
OK, since you asked for them, some stylistic comments
(I didn't reply in the first round since I couldn't come
up with an idea on what was actually failing and didn't
want to distract from the main question)
Comments inline:
> printf "destination is the serial number of a LaCie HDD connected by USB.\n";
> destination="10000E000D959403";
> printf 'destination=%s\n' "$destination";
# You quoted "$destination" and moved it to the right spot in printf: good
> if ! lsblk -o SERIAL | grep -F -- "$destination" > /dev/null ;
> then
> printf "destination device not connected ";
> printf "or the serial number is wrong. Aborting.\n";
> else
> printf "destination device is connected.\n"
> dev= lsblk --nodeps -o name,serial | grep -F -- "$destination" | cut -d ' '
> -f1 ;
> printf 'dev=%s is ready to receive backup.\n' "$dev";
> printf "Press any key to continue.\n";
> read -n 1 c;
> FTH;
> fi;
You worked in the suggestions elsethread, that's good. Especially the
quoting of "$destination" was a timebomb -- once the string contains
a space the script would stop working mysteriously, years after it
had been working. That "--" is similar: once $destination starta with
a dash, things go south. And so on.
One difficult thing in shells, when you come from other languages,
is to wrap one head's around variable substitution (and the other
expansions). The variable is expanded textually in place, it is not
a "placeholder". So
if ! lsblk -o SERIAL | grep -F -- $destination > /dev/null
(without the quotes) is first converted into
if ! lsblk -o SERIAL | grep -F -- 10000E000D959403 > /dev/null
Then, the command lsblk is invoked, and its result piped to
"grep -F -- $10000E000D959403 > /dev/null", for "if" to act on its
exit code. This would work, mind you. Now, if the value of destination
suddenly changes to
destination="1000 0E00 0D95 9403", the "if" line is first expanded
to
if ! lsblk -o SERIAL | grep -F -- 1000 0E00 0D95 9403 > /dev/null
...and the grep would see those unexpected arguments 0E00, 0D95 and
9403 (unexpected for us: for grep they would be just extra file names
to work on), so in the best case you'd get:
grep: 0E00: No such file or directory
grep: 0D95: No such file or directory
grep: 9403: No such file or directory
I wrote "best case" because, of course, you might have some files
named like that lying around: then, your script's behaviour starts
to get /really/ strange :-)
Another suggestion, more aesthetic: the semicolons at the end of
the lines are unnecessary. You only need one when putting two
lines together (as a replacement for a newline). For a reader of
your script they are confusing.
(A place where you might see it is in the construction
if <condition> ; then
do this
...
But you already separated the "if" and "then" by a newline, which
is perfectly fine, too.
Cheers
--
tomás
signature.asc
Description: PGP signature

