ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 what does symbol '^' do? Actually I want to store the letter hda/hdb/hdc/hdd into one of my variable in the script. Suppose I out the result of dmesg | grep '^hd' into a file say temp.txt, how do I extract the letter hda/hdb/.... into a variable in my script install.sh
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.
Simply, this gets the kernel ringbuffer, looks for lines beginning with 'hd<someletter>:', strips everything after and including the colon, sorts it, and removes duplicates.
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?
That may be much simpler, but I still choose to share my nice one-liner above.
[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.
Simply, this gets the kernel ringbuffer, looks for lines beginning with 'hd<someletter>:', strips everything after and including the colon, sorts it, and removes duplicates.
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.
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:
This tutorial assumes no previous knowledge of scripting or programming, but progresses rapidly toward an intermediate/advanced level of instruction . . . all the while sneaking in little snippets of UNIX® wisdom and lore. It serves as a textbook, a manual for self-study, and a reference and source of knowledge on shell scripting techniques. The exercises and heavily-commented examples invite active reader participation, under the premise that the only way to really learn scripting is to write scripts.
N=1
FILE=`mktemp`
ls -1d /proc/ide/hd? | while read dev
do echo IDE_${N}=`basename $dev` >> $FILE
N=$(($N+1))
done
source $FILE
rm $FILE
The FILE bit is a bit hackish, unfortunately, but it's pretty much the best way.
hi Matir, I need your help again. The above code gives me the devices hda hdb hdc and so on in variables IDE_1, IDE_2, IDE_3 and so on.
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.
Last edited by kushalkoolwal; 09-28-2005 at 11:17 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.