Is there an easy way to specify all mounted physical partitions in a script?
by JASlinux from LinuxQuestions.org on (#5PSJB)
This is my unmount all partitions script (I never have more than 7 per medium or 4 media total). The first argument tests if the mountpoint directory exists & if it does, it umounts the device. The directory could exist even if there's no mount, but generally there's only a directory if a device is mounted:
Code:#!/bin/sh
test -d /mnt/sda1 && umount /mnt/sda1
test -d /mnt/sda2 && umount /mnt/sda2
test -d /mnt/sda3 && umount /mnt/sda3
test -d /mnt/sda4 && umount /mnt/sda4
test -d /mnt/sda5 && umount /mnt/sda5
test -d /mnt/sda6 && umount /mnt/sda6
test -d /mnt/sda7 && umount /mnt/sda7
#
test -d /mnt/sdb1 && umount /mnt/sdb1
test -d /mnt/sdb2 && umount /mnt/sdb2
test -d /mnt/sdb3 && umount /mnt/sdb3
test -d /mnt/sdb4 && umount /mnt/sdb4
test -d /mnt/sdb5 && umount /mnt/sdb5
test -d /mnt/sdb6 && umount /mnt/sdb6
test -d /mnt/sdb7 && umount /mnt/sdb7
#
test -d /mnt/sdc1 && umount /mnt/sdc1
test -d /mnt/sdc2 && umount /mnt/sdc2
test -d /mnt/sdc3 && umount /mnt/sdc3
test -d /mnt/sdc4 && umount /mnt/sdc4
test -d /mnt/sdc5 && umount /mnt/sdc5
test -d /mnt/sdc6 && umount /mnt/sdc6
test -d /mnt/sdc7 && umount /mnt/sdc7
#
test -d /mnt/sdd1 && umount /mnt/sdd1
test -d /mnt/sdd2 && umount /mnt/sdd2
test -d /mnt/sdd3 && umount /mnt/sdd3
test -d /mnt/sdd4 && umount /mnt/sdd4
test -d /mnt/sdd5 && umount /mnt/sdd5
test -d /mnt/sdd6 && umount /mnt/sdd6
test -d /mnt/sdd7 && umount /mnt/sdd7Can it be written more efficiently?
Code:#!/bin/sh
test -d /mnt/sda1 && umount /mnt/sda1
test -d /mnt/sda2 && umount /mnt/sda2
test -d /mnt/sda3 && umount /mnt/sda3
test -d /mnt/sda4 && umount /mnt/sda4
test -d /mnt/sda5 && umount /mnt/sda5
test -d /mnt/sda6 && umount /mnt/sda6
test -d /mnt/sda7 && umount /mnt/sda7
#
test -d /mnt/sdb1 && umount /mnt/sdb1
test -d /mnt/sdb2 && umount /mnt/sdb2
test -d /mnt/sdb3 && umount /mnt/sdb3
test -d /mnt/sdb4 && umount /mnt/sdb4
test -d /mnt/sdb5 && umount /mnt/sdb5
test -d /mnt/sdb6 && umount /mnt/sdb6
test -d /mnt/sdb7 && umount /mnt/sdb7
#
test -d /mnt/sdc1 && umount /mnt/sdc1
test -d /mnt/sdc2 && umount /mnt/sdc2
test -d /mnt/sdc3 && umount /mnt/sdc3
test -d /mnt/sdc4 && umount /mnt/sdc4
test -d /mnt/sdc5 && umount /mnt/sdc5
test -d /mnt/sdc6 && umount /mnt/sdc6
test -d /mnt/sdc7 && umount /mnt/sdc7
#
test -d /mnt/sdd1 && umount /mnt/sdd1
test -d /mnt/sdd2 && umount /mnt/sdd2
test -d /mnt/sdd3 && umount /mnt/sdd3
test -d /mnt/sdd4 && umount /mnt/sdd4
test -d /mnt/sdd5 && umount /mnt/sdd5
test -d /mnt/sdd6 && umount /mnt/sdd6
test -d /mnt/sdd7 && umount /mnt/sdd7Can it be written more efficiently?