SolvedPrivate

How to have a script locate a specific hard drive.

Posted on 2013-06-11
7
199 Views
Last Modified: 2016-02-11
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.
0
Comment
Question by:Christopher Gay
  • 5
  • 2
7 Comments
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 39239534
lsscsi might do the trick
07:42:35$ lsscsi 
[2:0:4:0]    tape    HP       C1537A           L105  /dev/st0 
[3:0:0:0]    disk    ATA      WDC WD2500JD-00G 02.0  /dev/sda 
[5:0:0:0]    cd/dvd  HL-DT-ST CD-RW GCE-8240B  1.06  /dev/sr0 
[9:0:0:0]    cd/dvd  ATAPI    CD-ROM DRIVE-40X T0CP  /dev/sr1 
[9:0:1:0]    cd/dvd  HL-DT-ST DVD-RAM GSA-H22L 1.00  /dev/sr2 
[10:0:0:0]   disk    ATA      QUANTUM FIREBALL APL.  /dev/sdb 
[10:0:1:0]   cd/dvd  SAMSUNG  CD-ROM SC-152C   CS05  /dev/sr3 

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.
0
 
LVL 1

Author Comment

by:Christopher Gay
ID: 39242813
Unfortunately these unix boxes do not have lsscsi and I am unable to install it to them.
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 39244055
That's too bad. Never mind, it seems you can likely get enough from a shell script
#!/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

Open in new window

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

Open in new window

In case you're interested, I made up that script from the output of strace lsscsi. The file is attached
strace.txt
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 34

Expert Comment

by:Duncan Roe
ID: 39244062
This is Linux specific sorry. I just noticed you talk about Unix
0
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 500 total points
ID: 39246144
To address your original question: there is nothing in standard Unix that will meet your request. Any solution will involve architecture-specific extensions, such as I posted for Linux.
What is the architecture of your Unix systems? (FreeBSD, Solaris (x86/Sparc), HP-UX, Tru64, ...)
0
 
LVL 1

Author Comment

by:Christopher Gay
ID: 39248787
Duncan

Thanks for the information. I am running FreeBSD and have just updated it to 9.1.
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 39249397
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.
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question