I'm in need of some help (again) after you guys helped me wonderfully last time. I'm writing a script to test my HDD's with SmartCTL. So I can ofcourse copy the commands per disk, but it would be even more awesome if I can just set the disks once and the script does them one by one:
#!/bin/bash
date=`date +%d-%m-%Y-%T`
touch /var/log/disk/Disk-health-check-$date
disks="/dev/sda
/dev/sdb"
for disk in disks
do
wait=$(smartctl -t short $disk | awk '/Please wait/ {print $3}')
echo "waiting..."
sleep $((wait * 60 + 60))
echo "done"
smartctl --log=selftest $disk
smartctl -a $disk
done
exit
But unfortunately it only uses the /dev/sda, and not sdb, etc. So how can I make this works? Thanks in advance guys!!
for disk in $disks, notfor disk in disks. Though even that is bad practice.disks=( /dev/sda /dev/sdb ), and usefor disk in "${disks[@]}", for an array. And fix all the bugs shellcheck.net finds.YYYY-mm-ddas your date format. It's an ISO standard, and -- more importantly -- its ASCII sort order lines up with its sort order as a date, which is absolutely not true for the format you're trying to use here. Having ASCII sort order be correct makes it way easier to find the oldest or newest file, or every file older than a specific date, etc.