Some really weird Voodoo magic is going on with mdadm in my script:
Creating RAID with: mdadm --create --run --level=1 --metadata=1.2 --raid-devices=2 /dev/md/4 /dev/nvme1n1p4 /dev/nvme0n1p4
mdadm: /dev/nvme1n1p4 appears to contain an ext2fs file system
size=495889752K mtime=Thu Jan 1 01:00:00 1970
mdadm: /dev/nvme0n1p4 appears to be part of a raid array:
level=raid1 devices=2 ctime=Sun Jul 21 16:58:43 2024
mdadm: array /dev/md/4 started.
------------
Creating RAID with: mdadm --create --run --level=1 --metadata=1.2 --raid-devices=2 /dev/md/4 /dev/nvme1n1p4 /dev/nvme0n1p4 > /dev/null
mdadm: You have listed more devices (4) than are in the array(2)!
------------
Creating RAID with: mdadm --create --run --level=1 --metadata=1.2 --raid-devices=2 /dev/md/4 /dev/nvme1n1p4 /dev/nvme0n1p4 > /dev/null 2>&1
mdadm: You have listed more devices (5) than are in the array(2)!
Just look at the 2 lower examples where I try to mute the output of mdadm to only produce the output I want. It produces a completely unrelated error message.
Here is the bash section that causes the issue:
else \
echo "Continuing with Software RAID1"; \
for partition in {1..4}; do \
raidCommand="mdadm --create --run --level=1 --metadata=1.2 --raid-devices=${targetDriveCount} /dev/md/${partition} " && \
for drive in $targetDrives; do \
if [[ "$drive" == *nvme* ]]; then \
raidCommand="${raidCommand} ${drive}p${partition} "; \
else \
raidCommand="${raidCommand} ${drive}${partition} "; \
fi; \
done; \
raidCommand="${raidCommand} > /dev/null 2>&1" && \
echo "Creating RAID with: ${raidCommand}" && \
$raidCommand; \
done; \
fi && \
The script works, but this output is not clean at all. How can I prevent this from happening? And yeah I know, the script does not look great, but it should do for now. And yes, it actually is a single liner intentionally. But that does not explain the error in any way I can understand at all. What is going on?
$raidCommandperforms word splitting and globbing, but doesn't magically perform redirections - so>,/dev/null, and2>&1are all passed to mdadm as additional arguments\characters?{ … }),edit-and-execute-command(Ctrl+x, Ctrl+e) or even putting everything in a shell function and calling it.