1

I haven't had much luck finding the answer to my question. I would like to find the next logical empty mountpoint using the mountpoint command in Ubuntu. This will allow multiple occurrences of a script I am writing to automate some tasks.

#!/bin/bash
MNT="ewf"
COUNT=""
until mountpoint -q /mnt/"$MNT""$COUNT"
do
COUNT=$((COUNT+1))
echo "$MNT""$COUNT is a mountpoint"
done
echo "$MNT""$COUNT is not a mountpoint"

Where the loop would iterate through untill it found a empty mountpoint such as /mnt/ewf1. I've tried various possible solutions and this is the closest I think I have come. But I am unsure how to pass a statement as true or false without the usage of a boolean value in Bash.

The issue I have found with the above is the variable $COUNT is being declared as " " (space) so it is adding a character to /ewf prior to +1.

I am unsure how to correct it.

ImNotLeet
  • 381
  • 5
  • 19
  • The first loop should be checking `/mnt/ewf` and the second should check `/mnt/ewf1` no spaces involved. Are you sure that's happening? What do you see if you add `set -x` to the top of the script? – Etan Reisner May 12 '15 at 17:34
  • @EtanReisner It seems to be incriminating but I am unable to exit the loop with the true value, mountpoint -q /mnt/ewf### should return false and exit gracefully which it seems to be failing. `mountpoint -q /mnt/ewf3556 + COUNT=3557 + echo 'ewf3557 is a mountpoint' ewf3557 is a mountpoint + mountpoint -q /mnt/ewf3557` – ImNotLeet May 12 '15 at 18:24
  • I don't see any spaces there. I do see a **lot** of mountpoints though. I also see you incrementing `COUNT` before you print it which is confusing. – Etan Reisner May 12 '15 at 18:25

1 Answers1

1

Change until mountpoint ... to while mountpoint .... You want to skip entries that are mount points.

Stephen Gildea
  • 365
  • 1
  • 9