Exclude certain disk in dd command script for disk erasure

Posted on

Exclude certain disk in dd command script for disk erasure – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, bash, shell, aix, ksh.

 for disk in $(lspv | awk '{print $1}') ; do
   dd if=/dev/zero of=/dev/${disk} bs=1024 count=$(bootinfo -s ${disk})
   echo $disk wiped
done

How do i exclude certain disks like hdisk0,hdisk1 and hdisk3?

Regards,
Adel

Solution :

The simplest way would be:

for disk in $(lspv | awk '{print $1}') ; do
   case "$disk" in
      hdisk0|hdisk1|hdisk3)
          continue
          ;;
   *)
       dd if=/dev/zero of=/dev/${disk} bs=1024 count=$(bootinfo -s ${disk})
       echo $disk wiped
       ;;
   esac
done

Well, either explicitly list the disks you want to erase in your command, or add some kind of filter to your command.

Perhaps something like lspv | awk '!/regex/ {print $1}'

Leave a Reply

Your email address will not be published.