Ok, so this is a small part of a script I wrote to build disk groups using VXVM. The only problem is that I am limited to a count of 8 maximum. If I want more, I will have to add more lines of "if" statements. How can I accomplish the same thing, in a few lines, but not be limited in the max count?
In this case, $NUMBER = 8
echo "There are $TOTAL2 $DISKTYPE disks of this size available."
echo
echo "How many do you want to use(8 disks max!)"
print -n "to create your diskgroup? :"
read NUMBER
if [ $NUMBER -eq 1 ]
then
continue
# exit
fi
if [ $NUMBER -eq 2 ]
then
alphabet="02"
count=0
fi
if [ $NUMBER -eq 3 ]
then
alphabet="02 03"
count=0
fi
if [ $NUMBER -eq 4 ]
then
alphabet="02 03 04"
count=0
fi
if [ $NUMBER -eq 5 ]
then
alphabet="02 03 04 05"
count=0
fi
if [ $NUMBER -eq 6 ]
then
alphabet="02 03 04 05 06"
count=0
fi
if [ $NUMBER -eq 7 ]
then
alphabet="02 03 04 05 06 07"
count=0
fi
if [ $NUMBER -eq 8 ]
then
alphabet="02 03 04 05 06 07 08"
count=0
fi
for letter in $alphabet
do
count=`expr $count + 1`
echo "$letter"
done > count.txt
Thanks for the reply. It definitely takes up less space, but I am still limited to a count of 8. I could add more lines, but I don't want to be limited by the number of lines I have in the file.
Count will 'default' to zero, you do not set it for the first condition. But, you feel you must set within each case possibility? Why?
Couldn't you set it just once outside of the case statement?
Also, is your pupose here to simply create the count.txt file? There are easier ways to accomplish that.
I suppose you are correct. I put the counts back because of a syntax error I was getting. Let me try the script by taking out all counts, and putting it outside the "tree".
A 'continue' is normally only used (and needed) while inside some kind of loop - causing the execution to skip the rest of the processing and continue with the next iteration. Thus, your 'continue' may be not needed.
What is you final desired result? That count.txt file?
I put the counts back because of a syntax error I was getting.
What error?? don't forget you need the keep the ;; in each of the selections for a case statement.
If you really want to be unlimited, why use if or case?
You could set a variable, say MAX_CNT to the input supplied to your script,
set alphabet=2, and create a "while loop <less than or equal to MAX_CNT" add one more to alphabet. This way there's no limit at all to your script.
The output of count.txt when $NUMBER is 6:
02
03
04
05
06
And here is the ultimate goal of all the counting (the output of the disk adding script I wrote is below)
NOTE: I commented out the actual lines that add the disks, so there will be a few errors below due to the fact that it is not actually adding disks, but only printing the commands to screen.:
This script is only to be used when building NEW DISK GROUPS ONLY!!
that will be using VXVM 4.1 or higher to manage disks, with no rootdg.
This version is an option for striping.
Have you ran the inq script?
Enter 'y' for Yes or 'n' for No :y
Chose the type of external storage
you will be working with. Your choices
are 'EMC' and 'EVA' (EVA = HSV).
Enter 'EMC' or 'EVA'. Disk type? :eva
Disk sizes that are available are:
524288000
What size disk do you want to use?
Disk size? :524288000
There are 11 HSV disks of this size available.
How many do you want to use(20 disks max!)
to create your diskgroup? :6
What will the name of y our diskgroup?
Ensure that the name of your diskgroup
ends with 'dg', or there will be problems!!!
For example(s).. 'datadg'...or 'p1vma1c1dg'.
Diskgroup Name :fakedg
vxdg init fakedg fakedg01=c10t0d6
vxdg -g fakedg adddisk fakedg02=c10t0d7
vxdg -g fakedg adddisk fakedg03=c10t1d0
vxdg -g fakedg adddisk fakedg04=c10t1d1
vxdg -g fakedg adddisk fakedg05=c10t1d2
vxdg -g fakedg adddisk fakedg06=c10t1d3
Are you ready to create a lvol in fakedg?
Enter 'y' for Yes or 'n' for No :y
Enter the name of your lvol.
Lvol name :fakelvol
Enter the size of your lvol.
The maximum size is: -1149269920 or -1096G <-- Wrong value is due to a bug in the script when I use 5 or more disks...
Lvol size :2G
Enter the block size of your lvol.
Lvol block size :8192
Do you need to do any striping?
Enter 'y' for Yes or 'n' for No :y
What is the size of your strpewidth?
Stripewidth size :128
What is the number of disks that will be striped across?
NOTE: You just created diskgroup fakedg with 6 disks.
Enter a value for 'nstripe' :6
vxassist -g fakedg make fakelvol 2G fakedg01 fakedg02 fakedg03 fakedg04 fakedg05 fakedg06 layout=stripe nstripe=6 stripewidth=128
mkfs -F vxfs -o largefiles -o bsize=8192 /dev/vx/dsk/fakedg/fakelvol
VxVM vxassist ERROR V-5-1-607 Diskgroup fakedg not found
VxVM vxassist ERROR V-5-1-607 Diskgroup fakedg not found
This is how much space you have left in the diskgroup fakedg:
<Nothing listed here, because script is not actually executing the commands>
This is the max size your lvol can be:
<Nothing listed here, because script is not actually executing the commands>
Do you want to max out the size of your lvol?
Enter 'y' for Yes or 'n' for No :n
because, you can do you lv stuff while inside the loop. In this case, I touch'ed files to create/put timestamp. See the following as output from execution
> alpha1
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma02
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma03
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma04
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma05
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma06
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma07
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma08
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma09
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma10
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma11
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma12
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma13
The %.2d says to format for two digits, thus can allocate from device _02 to _99. If you want to be able to go past this, simply change the script to %.3d before you execute. (Your example seemed to skip over the possibility of a _01 device.)
However, I would find it unusual to think you would be configuring more than 99 devices.
Before implementing this or any other suggestions, strongly recommend 'trial runs' where you do not execute the commands, but display/print the commands you are about to run.
Ok, so this is how I ended up using it in my script. Of course I had to change a couple of other things to make it work but it works great!!!
## Increment the disk counter based on $NUMBER, and output to disks3.txt
> disks3.txt
CURRENT=0
while [ $CURRENT -le $NUMBER ]
do
if [ $CURRENT -gt 1 ]
then
lv_val=$(printf "%.2d" $CURRENT)
##Capture disk names, all except the first disk in the disk group
echo ${DISKGROUP}$lv_val >> disks3.txt
fi
CURRENT=$(($CURRENT + 1))
done