1830233 Members
1897 Online
109999 Solutions
New Discussion

shell script

 
SOLVED
Go to solution
Leovino A. Trinidad, Jr
Frequent Advisor

shell script

Hi!

How can you detect/check which drive (dev/hda or /dev/hdc) is up using a script?

I'm making an offline disk mirroring script using dd command. Offline disk mirroring in the sense that the mirroring is a scheduled type of backup (not like the usual one which is a realtime mirroring - to avoid crashes when certain patch is applied and it can boot either of the drives at once).

Hope you can help me.

Regards

LAT
4 REPLIES 4
Francisco J. Soler
Honored Contributor
Solution

Re: shell script

Hi LAT,

For be up, do you mean mounted?

If so, you can try this one:

ACTIVEA=`df | grep /dev/hda | wc -l`
ACTIVEC=`df | grep /dev/hdc | wc -l`

If ACTIVEA is 0 (zero) there is nothing mounted in /dev/hda, the same for ACTIVEC

HTH
Frank
Linux?. Yes, of course.
Leovino A. Trinidad, Jr
Frequent Advisor

Re: shell script

Hi!

thanks for the help! Just want to make a correction on the declaration of the variable it should be

ACTIVEA=$(df|grep /dev/hda|wc -l)
ACTIVEC=$(df|grep /dev/hdc|wc -l)

instead of

ACTIVEA='df|grep /dev/hda|wc -l' -- this will have a string result.

Regards,

LAT



Caesar_3
Esteemed Contributor

Re: shell script

Hello!

Lets say that this depend on the shell
that script is for (sh/bash/csh/ksh)

And yes you can do this.

Caesar
Francisco J. Soler
Honored Contributor

Re: shell script

Hi LAT,

If you don't want a sting value, your correction is right. Good correction.

On the other hand FYI, you can obtain useful information about the system in the virtual /proc file system. For example, if you issue:

cat /proc/modules, you get information about loaded kernel modules. Or

cat /proc/meminfo, you get information about the used memory in the system.

Or about the partitions you have "used" you can type: cat /proc/partitions and pipe the output through a grep like in df command.

Regards.
Frank.

Linux?. Yes, of course.