So I want to build a useful shell script, using sh, that will provide a menu to run SMART tests on a hard drive. The intent is to have this on a bootable USB drive and run it on various computers. Since the exact computer disk configuration will be unknown, I will need a way to scan for the drives, then pipe that information into the script to be called upon with the actual test. I am using FreeBSD and the smartmontools package, but my scripting questions aren't really unique to that platform. I'm fairly new to shell scripting, but this is a great opportunity for me to learn and expand my skills.
Right now, I'm stuck on how to get the specific information called into a variable to use with the menu.
On my VM, If I run
I get returned
/dev/cd0 -d atacam # /dev/cd0, ATA device
/dev/da0 -d scsi # dev/da0, SCSI device
Of course, this is far more information than I want to pass on, as the testing commands will only take the "/dev/device" portion.
I figured out that if I have in the script
I get returned
/dev/cd0
/dev/da0
Ok, this is useful, but how do I pass the results in the script so I can choose just a single line? Since this input will be variable depending on the computer it is used on (my laptop drive is /dev/ada0, my desktop has multiple drives, /dev/nvme0, /dev/nvme1 /dev/ada0) I really can't hardcode the varibles.
Any advice?
Right now, I'm stuck on how to get the specific information called into a variable to use with the menu.
On my VM, If I run
Code:
smartctl --scan
/dev/cd0 -d atacam # /dev/cd0, ATA device
/dev/da0 -d scsi # dev/da0, SCSI device
Of course, this is far more information than I want to pass on, as the testing commands will only take the "/dev/device" portion.
I figured out that if I have in the script
Code:
smartctl --scan | awk '{print $1}'
/dev/cd0
/dev/da0
Ok, this is useful, but how do I pass the results in the script so I can choose just a single line? Since this input will be variable depending on the computer it is used on (my laptop drive is /dev/ada0, my desktop has multiple drives, /dev/nvme0, /dev/nvme1 /dev/ada0) I really can't hardcode the varibles.
Any advice?