Redirect hdparm output to grep?
Michele Sanges
michele.sanges at otomelara.it
Wed May 14 06:50:19 UTC 2008
Il giorno mar, 13/05/2008 alle 22.48 -0700, Alan Dayley ha scritto:
> In a shell script I want to do something based on the presence or not
> of a USB mounted partition. hdparm can indirectly report this
> information with a partition rescan like this:
>
> hdparm -z /dev/sda
>
> I want to then parse the output of this command to determine if a
> partition was found or not. My proposed command is:
>
> /bin/hdparm -z /dev/sda | grep -c sda1
>
> This should return a count of the string "sda1" in the output from
> hdparm, But, it does not work. First it appears that most of the
> hdparm output goes to stderr instead of stdout. Secondly the various
> piping combinations I have tried don't produce output to grep.
>
> Below are examples of what I have tried, exposing my shell scripting
> ignorance. Note that the command lines with a pipe to grep end with a
> "0" which is grep's contribution to the output. It is always "0" even
> if the sought text is present. The attempted pipes to a file are even
> worse syntax, I'm sure.
>
> This question is not necessarily a Busybox issue even though both
> hdparm and grep in use here are from Busybox. I may just not have the
> shell scripting chops to know the right syntax. Anyone have any
> thoughts or education to give me?
>
> Alan
Maybe I have not understood but do you want see if the device /dev/sda1
is mounted somewhere?
What about:
mount | grep sda1
Regards.
Michele
More information about the busybox
mailing list