Visit Our UNIX and Linux User Community


Help me streamline this counting part of my script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me streamline this counting part of my script.
# 8  
Old 02-26-2008
Yes, it worked. Thank you. Here is what I did:
Code:
## Increment the counter based on NUMBER, and output to count.txt
case $NUMBER
   in
       1) continue ;;

       2) alphabet="02";;
       3) alphabet="02 03";;
       4) alphabet="02 03 04";;
       5) alphabet="02 03 04 05";;
       6) alphabet="02 03 04 05 06";;
       7) alphabet="02 03 04 05 06 07";;
       8) alphabet="02 03 04 05 06 07 08";;
       9) alphabet="02 03 04 05 06 07 08 09";;
      10) alphabet="02 03 04 05 06 07 08 09 10";;
      11) alphabet="02 03 04 05 06 07 08 09 10 11";;
      12) alphabet="02 03 04 05 06 07 08 09 10 11 12";;
      13) alphabet="02 03 04 05 06 07 08 09 10 11 12 13";;
      14) alphabet="02 03 04 05 06 07 08 09 10 11 12 13 14";;
      15) alphabet="02 03 04 05 06 07 08 09 10 11 12 14 14 15";;
      16) alphabet="02 03 04 05 06 07 08 09 10 11 12 13 14 15 16";;
      17) alphabet="02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17";;
      18) alphabet="02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18";;
      19) alphabet="02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19";;
      20) alphabet="02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20";;
esac
count=0
for letter in $alphabet
do
    count=`expr $count + 1`
    echo "$letter"
done > count.txt

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.:

Code:
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


Last edited by LinuxRacr; 02-26-2008 at 08:15 PM..
# 9  
Old 02-26-2008
Hammer & Screwdriver A different approach (actually, two!)

Here is the new script

Code:
> cat alpha1
#! /bin/bash

#remove old files
rm count.txt 2>/dev/null
rm p1vma* 2>/dev/null

#set the variable
NUMBER=13
CURRENT=0
while [ $CURRENT -le $NUMBER ]
   do
      if [ $CURRENT -gt 1 ]
         then
#         printf "%.2d \n" $CURRENT
         printf "%.2d \n" $CURRENT >>count.txt
         lv_val=$(printf "%.2d" $CURRENT)
#do lv stuff here
         touch p1vma$lv_val
      fi
      CURRENT=$(($CURRENT + 1))
done

#see the files just created
ls -l p1vma*

It creates the count.txt file, although not sure if truly needed...
Code:
> cat count.txt
02 
03 
04 
05 
06 
07 
08 
09 
10 
11 
12 
13

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

Code:
> 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

# 10  
Old 02-26-2008
Before I try, how scalable is this? Does this take away the limit of disks I can add?
# 11  
Old 02-26-2008
Hammer & Screwdriver Limits only by the mask values

Code:
#         printf "%.2d \n" $CURRENT
         printf "%.2d \n" $CURRENT >>count.txt
         lv_val=$(printf "%.2d" $CURRENT)

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.
# 12  
Old 02-26-2008
Quote:
Originally Posted by joeyg
Code:
#         printf "%.2d \n" $CURRENT
         printf "%.2d \n" $CURRENT >>count.txt
         lv_val=$(printf "%.2d" $CURRENT)

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.
I totally agree. The output above from the script are just the commands echoed to screen. This clarifies a couple of things. Thanks for your replies!
# 13  
Old 02-26-2008
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!!!

Code:
## 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

# 14  
Old 10-20-2008
Sorry to bump an old thread, but how would I get the output in hexidecimal?

Previous Thread | Next Thread
Test Your Knowledge in Computers #294
Difficulty: Easy
Ubuntu is a free and open-source Linux distribution based on Slackware.
True or False?

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Streamline script to search for numbers in a certain range

Hello all, I need help making a script run faster since I have a huge file to sift through. The file I am running my script on looks like this: 1 -1.9E+001 -1.8E-001 1.5E+001 3.32E+001 2 -1.7E+001 -1.0E-002 1.2E+001 6.37E+001 3 -1.5E+001 -3.8E-006 6.7E+001 4.81E+001 The... (12 Replies)
Discussion started by: butson
12 Replies

2. Shell Programming and Scripting

counting in shell script

hi i am writing a korn shell script to compile all programs there are arount 2000+ files now i have a script that can compile programs but i want to show status of compilation because to compile all programs it takes around 10-15 mins so how can i display status like it should print no of files... (3 Replies)
Discussion started by: zedex
3 Replies

Featured Tech Videos