shell script to detect IDE devices
Hi folks,
Actually I am writing a shell script on Debian Linux which will do several tasks like copying, extracting, installing grub and all that. One of the task that I have to do first is to recognize the IDE devices that are attach to the system. Does any one know how can I write a simple shell script which will recognize what devices are connected to hda,hdb,hdc,hdd. I just need to probe for the IDE devices(Hard disk,CD-ROM,) that are attach to the system. Or is there any file/log in the system which maintains what/where IDEdevices are connected(hda/hdb/hdc/hdd). thanks |
Look at
Code:
dmesg | grep '^hd' |
Quote:
thanks |
The letter '^' indicates that the pattern MUST be at the beginning of a line. If you would like a list of all hd devices on the system, here's a code snippet you might like. :)
Code:
dmesg | egrep '^hd.?:' | cut -d':' -f1 | sort | uniq Note that this will only work if the kernel ringbuffer has not yet been filled to the point that those lines have been removed. Alternatively, and I feel stupid for forgetting this, you could try: Code:
ls -1d /proc/ide/hd? |
[QUOTE]Originally posted by Matir
[B]The letter '^' indicates that the pattern MUST be at the beginning of a line. If you would like a list of all hd devices on the system, here's a code snippet you might like. :) Code:
dmesg | egrep '^hd.?:' | cut -d':' -f1 | sort | uniq Excellent!!! I was looking exactly something like this. You seem to be an expert in this. Well my second phase of the problem is how to read the out of your one-line command into some Variables in my script. Suppose I get the output from the command as: hda hdb How do I store each of them in variable like IDE_1 and IDE_2 in my shell script. Many thanks to you. |
Code:
N=1 |
Thanks a bunch Matir. You are the man.....
Can you give me some pointers to resources where I can learn basic and advanced shell scripting....... Thank you once again. |
The best way to learn shell scripting is to do it. That being said, you need some references to get you going. My favorite is the Advanced Bash-Scripting Guide. Don't let the word Advanced scare you off, it's quite good. To quote from it:
Quote:
|
Quote:
Now I would like to have a complete information of the devices like this in three variables or more depending upon the number of devices in my system: hda: WDC WD800BB-22JHC0, ATA DISK drive hdb: HITACHI CDR-8130, ATAPI CD/DVD-ROM drive hdc: SILICONSYSTEMS INC 1GB, ATA DISK drive I have copy pasted the above 3 lines from the output of this command(which you gave me earlier) dmesg | egrep '^hd.?:' The entire output of this command was: debian:~/Scripts# dmesg | egrep '^hd.?:' hda: WDC WD800BB-22JHC0, ATA DISK drive hdb: HITACHI CDR-8130, ATAPI CD/DVD-ROM drive hda: max request size: 128KiB hda: 156301488 sectors (80026 MB) w/2048KiB Cache, CHS=65535/16/63, UDMA(33) hdc: SILICONSYSTEMS INC 1GB, ATA DISK drive hdc: max request size: 128KiB hdc: 2046240 sectors (1047 MB) w/0KiB Cache, CHS=2030/16/63, DMA hdb: ATAPI 16X CD-ROM drive, 128kB Cache, DMA Any help will be greatly appreciated. |
All times are GMT -5. The time now is 09:38 AM. |