Christopher Gay
asked on
How to have a script locate a specific hard drive.
I am trying to write a shell script to perform some file maintenance on a model of hard drives that I have on several unix boxes. Is there any specific variable that the hard drives report to the OS that I could have the script look for to target these drives if I do not know the name of the volume on each box?
Currently I am just loading the script on that drive and allowing it to work but I would like to be able to just send it to my customer and have them run it without worrying that they got it on the correct drive or doing it myself.
Just in case this differs by manufacturer these are specifically Seagate drives.
Currently I am just loading the script on that drive and allowing it to work but I would like to be able to just send it to my customer and have them run it without worrying that they got it on the correct drive or doing it myself.
Just in case this differs by manufacturer these are specifically Seagate drives.
ASKER
Unfortunately these unix boxes do not have lsscsi and I am unable to install it to them.
That's too bad. Never mind, it seems you can likely get enough from a shell script
strace.txt
#!/bin/sh
main()
{
for i in $(ls /sys/bus/scsi/devices);do echo $i|grep '^[1-9]' >/dev/null 2>&1 && process_target $i;done
}
process_target()
{
cd /sys/bus/scsi/devices/$1
[ -d block ] || return
echo $(cat vendor) $(cat model) /dev/$(ls block)
}
main
The output looks like
20:41:35$ ~/tests/ee103.sh
ATA QUANTUM FIREBALL /dev/sdb
SAMSUNG CD-ROM SC-152C /dev/sr3
ATA WDC WD2500JD-00G /dev/sda
HL-DT-ST CD-RW GCE-8240B /dev/sr0
ATAPI CD-ROM DRIVE-40X /dev/sr1
HL-DT-ST DVD-RAM GSA-H22L /dev/sr2
In case you're interested, I made up that script from the output of strace lsscsi. The file is attachedstrace.txt
This is Linux specific sorry. I just noticed you talk about Unix
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Duncan
Thanks for the information. I am running FreeBSD and have just updated it to 9.1.
Thanks for the information. I am running FreeBSD and have just updated it to 9.1.
I think your best course of action is to post a fresh question making it clear you need a solution for FreeBSD. It's far more important to know that than to know we're looking for a Seagate drive.
I suggest a new Q because the chances of anyone else looking through this Q is rather low now, and I don't know FreeBSD at all well. I would title it something like "FreeBSD - how to determine hard drive models programatically" - don't limit yourself to scripting because the information may only be available to a program.
I suggest a new Q because the chances of anyone else looking through this Q is rather low now, and I don't know FreeBSD at all well. I would title it something like "FreeBSD - how to determine hard drive models programatically" - don't limit yourself to scripting because the information may only be available to a program.
Open in new window
Your script could grep for the disk you want from this output. I have a recent Linux which presents all disks as scsi even if they are ide - you might want to check whether your systems behave likewise. The information comes from the /sys jungle - column 3 is supposed to be Vendor but as you can see it only sometimes is. Still, you get the model.