[#] Wyciąganie podstawowych informacji o dyskach i partycjach

( Ostatnio zmieniony sob., 10/01/2009 - 01:07 )
 

skrypcik.sh

#!/bin/sh

#########


# List all CD-ROMs by using /proc entries
list_cdrom_devices()
{
   for CDDEVICE in `cat /proc/sys/dev/cdrom/info 2>/dev/null | head -n 3 | tail -n 1 | cut -d ":" -f 2`; do
      echo "/dev/$CDDEVICE"
   done
}

# List all devices with filesystems
list_partition_devices()
{
   cat /proc/partitions | grep -v loop | sed -r "s/^[0-9 ]+/\\/dev\\//" | grep /dev/ | egrep "[0-9]"
}

# List all devices with filesystems
list_special_partition_devices()
{
   blkid -t TYPE="ntfs" | cut -d : -f 1
}

# List all disk devices
list_disk_devices()
{
   cat /proc/partitions | grep -v loop | sed -r "s/^[0-9 ]+/\\/dev\\//" | grep /dev/ | egrep -v "[0-9]"
}

# List all partitions marked as Linux Swap
list_swap_devices()
{
   blkid -t TYPE="swap" | cut -d : -f 1
}

# List all block devices
list_devices()
{
   echo -e "\n***************cdrom's ***************"
   list_cdrom_devices
   echo -e "\n***************partitions ***************"
   list_partition_devices
   echo -e "\n***************special partitions ***************"
   list_special_partition_devices
   echo -e "\n***************partitions swap ***************"
   list_swap_devices
   echo -e "\n***************disks ***************"
   list_disk_devices
}

list_devices

Wynik:

***************cdrom's ***************
/dev/sr0

***************partitions ***************
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
/dev/sda5
/dev/sda6

***************special partitions ***************
/dev/sda1

***************partitions swap ***************
/dev/sda6

***************disks ***************
/dev/sda
5
Twoja ocena: Brak Średnio: 5 (2 głosy)