# blkid --uuid 2026-01-19-03-28-45-00
/dev/sdc
Meaning that the block device with that UUID is connected to the system.
When this executes,
destination="2026-01-19-03-28-45-00";
printf "destination=$destination\n";
if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
printf "destination device not connected. Aborting.\n"
else
printf "destination device is connected.\n"
dev="$( blkid --uuid $destination )";
printf "dev=$dev\n";
# FTH;
fi;
this is the output.
destination=2026-01-19-03-28-45-00
destination device not connected. Aborting.
With the device being present, I expect this. destination=2026-01-19-03-28-45-00
destination device is connected.
dev=/dev/sdc
Does this line have a syntax error?
if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
Does this line have a syntax error?
if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
# blkid --uuid 2026-01-19-03-28-45-00Is this a real uuid or redacted one? Its syntax is strange for me.
/dev/sdc
Meaning that the block device with that UUID is connected to the system.
When this executes,
destination="2026-01-19-03-28-45-00";
printf "destination=$destination\n";
if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
printf "destination device not connected. Aborting.\n"
else
printf "destination device is connected.\n"
dev="$( blkid --uuid $destination )";
printf "dev=$dev\n";
# FTH;
fi;
this is the output.
destination=2026-01-19-03-28-45-00
destination device not connected. Aborting.
With the device being present, I expect this. destination=2026-01-19-03-28-45-00
destination device is connected.
dev=/dev/sdc
Does this line have a syntax error?
if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
Thanks, ... P.
destination="2026-01-19-03-28-45-00";
printf "destination=$destination\n";
if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
dev="$( blkid --uuid $destination )";
printf "dev=$dev\n";
this is the output.
destination=2026-01-19-03-28-45-00
destination device not connected. Aborting.
With the device being present, I expect this. destination=2026-01-19-03-28-45-00
destination device is connected.
dev=/dev/sdc
Does this line have a syntax error?
if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
From a private message,
I modified your script slightly and it works for me.
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.
OK in a simple test. Suggestions always welcome. Something may be
more efficient than the long pipeline.
lsblk --nodeps -o name,serial | grep -F -- "$destination" | cut -d ' ' -f1
Hello again,OK, since you asked for them, some stylistic comments
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.
printf "destination is the serial number of a LaCie HDD connected by USB.\n"; destination="10000E000D959403";# You quoted "$destination" and moved it to the right spot in printf: good
printf 'destination=%s\n' "$destination";
if ! lsblk -o SERIAL | grep -F -- "$destination" > /dev/null ;You worked in the suggestions elsethread, that's good. Especially the
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;
# blkid --uuid 2026-01-19-03-28-45-00
/dev/sdc
Meaning that the block device with that UUID is connected to the system.
When this executes,
destination="2026-01-19-03-28-45-00";
printf "destination=$destination\n";
if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
printf "destination device not connected. Aborting.\n"
else
printf "destination device is connected.\n"
dev="$( blkid --uuid $destination )";
printf "dev=$dev\n";
# FTH;
fi;
this is the output.
destination=2026-01-19-03-28-45-00
destination device not connected. Aborting.
With the device being present, I expect this. destination=2026-01-19-03-28-45-00
destination device is connected.
dev=/dev/sdc
Does this line have a syntax error?
if ! ( lsblk -alno UUID | grep $destination > /dev/null ); then
# blkid --uuid 2026-01-19-03-28-45-00
/dev/sdc
Meaning that the block device with that UUID is connected to the system.
You should run your script through Shellcheck. It will tell you about the obvious problems, like quoting variables.
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.
What?
2026-01-19-03-28-45-00. Shorter than a UUID for a file system.
This looks like a timestamp.
lsblk --nodeps -o name,serial | grep -F -- "$destination" | cut -d ' ' -f1
So... you *have* the serial number (somehow) ...
The obvious way would be to use awk: ...
awk -v isn't 100% safe with all inputs, but if your serial number is reasonable (alphanumeric, maybe with some basic punctuation, but no backslashes or control characters) it should be OK.
| Sysop: | Jacob Catayoc |
|---|---|
| Location: | Pasay City, Metro Manila, Philippines |
| Users: | 5 |
| Nodes: | 4 (0 / 4) |
| Uptime: | 22:32:17 |
| Calls: | 117 |
| Calls today: | 117 |
| Files: | 367 |
| D/L today: |
560 files (257M bytes) |
| Messages: | 70,898 |
| Posted today: | 26 |