- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Please help me achieve Streamlined Counting
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2008 01:37 PM
02-25-2008 01:37 PM
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
Here is the output of count.txt:
02
03
04
05
06
07
08
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2008 01:42 PM
02-25-2008 01:42 PM
Re: Please help me acheive Streamlined Counting
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2008 01:59 PM
02-25-2008 01:59 PM
Re: Please help me acheive Streamlined Counting
You could generate your output along these lines:
# cat ./makecount
#!/usr/bin/sh
MIN=2
MAX=20
echo "Enter base value \c"
read i
while (( $i <= MAX ))
do
printf ">>> %02d\n" $i
let i=i+1
done
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2008 03:30 PM
02-25-2008 03:30 PM
Re: Please help me acheive Streamlined Counting
MIN=$NUMBER
MAX=$NUMBER
while (( $NUMBER <= MAX ))
do
printf ">>> %02d\n" $NUMBER
let NUMBER=NUMBER+1
done > count.txt
The output of count.txt is now:
>>> 08
Something is wrong....
If the variable $NUMBER=8, then the output should be:
02
03
04
05
06
07
08
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2008 04:11 PM
02-25-2008 04:11 PM
Re: Please help me acheive Streamlined Counting
#!/usr/bin/sh
echo "Enter minimum value \c"
read MIN
echo "Enter miximum value \c"
read MAX
while (( $MIN <= MAX ))
do
printf ">>> %02d\n" $MIN
let MIN=MIN+1
done
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2008 04:30 PM
02-25-2008 04:30 PM
Re: Please help me acheive Streamlined Counting
I supposed I should tell the purpose of the output from count.txt. It getting used later in the script so that that this happens:
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
vxdg -g fakedg adddisk fakedg07=c10t1d4
vxdg -g fakedg adddisk fakedg08=c10t1d5
Does this change anything?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2008 04:34 PM
02-25-2008 04:34 PM
Re: Please help me acheive Streamlined Counting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2008 11:17 PM
02-25-2008 11:17 PM
Re: Please help me acheive Streamlined Counting
case $NUMBER
in
1) continue ;;
2) alphabet="02"
count=0 ;;
3) alphabet="02 03"
count=0 ;;
4) alphabet="02 03 04"
count=0 ;;
5) alphabet="02 03 04 05"
count=0 ;;
6) alphabet="02 03 04 05 06"
count=0 ;;
7) alphabet="02 03 04 05 06 07"
count=0 ;;
8) alphabet="02 03 04 05 06 07 08"
count=0 ;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 03:06 AM
02-26-2008 03:06 AM
Re: Please help me acheive Streamlined Counting
perhaps this example may help:
#!/usr/bin/sh
typeset -Z2 i=01
typeset -i NUMBER=0
NUMBER=9
OUT=./count.txt
case $NUMBER in
1) continue;;
*) while [ $i -lt $NUMBER ]
do
i=$(($i + 1))
echo $i
done >>$OUT
;;
esac
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 09:07 AM
02-26-2008 09:07 AM
Re: Please help me acheive Streamlined Counting
I see that you are using /usr/bin/sh for the script. Is this supposed to work in ksh?
I incorperated this into my script, and it broke a couple of things. I think the problem is that the $NUMBER variable was set earlier in my script, and this modifies it, things get thrown off. What exactly is the typeset stuff for?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 09:29 AM
02-26-2008 09:29 AM
Re: Please help me acheive Streamlined Counting
typeset -Z2 i=01
typeset -i NUMBER=0
NUMBER=`cat number.txt`
OUT=count.txt
case $NUMBER
in
1) continue ;;
*) while [ $i -lt $NUMBER ]
do
i=$(($i + 1))
echo $i
done > $OUT
;;
esac
Here is the output of count.txt when $NUMBER is 5:
02
03
04
05
The problems I encounter is later in the script, where I have a function setup to do the following:
## Create a function that adds the sizes of all your disks together, and subtracts 5104.
NUMBER=`cat number.txt`
function adder_func
{
TYPE=$1
if [ -s sizes.$TYPE ]; then
let sum=0
for i in `cat sizes.$TYPE`
do
((i=$i - 5104))
((new_sum=$i + $sum))
sum=$new_sum
done
((last_sum=$new_sum * $NUMBER))
echo ${last_sum}
else
break
fi
}
## Call the adder_func function and output to value.txt to get the max size for your lvol.
adder_func size > value.txt
Here is the output of sizes.size:
524288000
Here is the output of value.txt
20
Based on the function, the output of value.txt should be:
2621414480
Just to make sure I ran the numbers:
root@server:/root_home> bc -l
524288000-5104
524282896
524282896*5
2621414480
Under the old way I was doing the count, it was working just fine. Now the number is off, and I don't know why. Please help!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 09:56 AM
02-26-2008 09:56 AM
Re: Please help me acheive Streamlined Counting
http://www.unix.com/showthread.php?p=302170700&posted=1#post302170700
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 11:47 AM
02-26-2008 11:47 AM
Re: Please help me acheive Streamlined Counting
#!/usr/bin/sh is the posix shell
The posix-shell enables use of typeset for variable definition, which may also work in ksh. However, the basic idea in
typeset -Z2 i=01
is to define a two-field integer, where a one digit number is preceded by zero
The other definition
typeset -i NUMBER=0
simply marks NUMBER as an integer, which I thought looked quite natural under the circumstances, but if it breaks something later in your script it is probably because of attempts of assigning other than pure integers to it.
Could you please post an example of the content of sizes.$TYPE
And what goes wrong in the adder_func?
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2008 12:49 PM
02-26-2008 12:49 PM
Re: Please help me acheive Streamlined Counting
$TYPE=size when I run the function:
adder_func size > value.txt
So sizes.$TYPE becomes sizes.size.
Here is the output of sizes.size:
524288000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 12:16 AM - edited 09-06-2011 07:07 AM
02-27-2008 12:16 AM - edited 09-06-2011 07:07 AM
Re: Please help me achieve Streamlined Counting
>john: typeset -Z2 i=01
>is to define a two-field integer, where a one digit number is preceded by zero
Be very careful about using this trick. This caused errors for set_parms for the years 08 and 09:
http://h30499.www3.hp.com/t5/System-Administration/Change-the-System-Date-and-Time-in-11-31/m-p/4150450
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 07:51 AM
02-27-2008 07:51 AM
Re: Please help me acheive Streamlined Counting
-----------------------------------------------
## 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
---------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2008 04:27 PM - edited 09-06-2011 07:07 AM
02-27-2008 04:27 PM - edited 09-06-2011 07:07 AM
Re: Please help me achieve Streamlined Counting
CURRENT=$(($CURRENT + 1))
You can simplify this to:
(( CURRENT += 1 ))
And if you want performance add at the top:
typeset -i CURRENT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 11:27 AM
10-21-2008 11:27 AM
Re: Please help me acheive Streamlined Counting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 11:46 AM
- Tags:
- printf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 11:48 AM
10-21-2008 11:48 AM
Re: Please help me acheive Streamlined Counting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 11:49 AM
10-21-2008 11:49 AM
Re: Please help me acheive Streamlined Counting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 12:21 PM
10-21-2008 12:21 PM
Re: Please help me acheive Streamlined Counting
#printf "%02x0000\n" 10
0a0000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2008 02:49 PM - edited 09-06-2011 07:08 AM
10-21-2008 02:49 PM - edited 09-06-2011 07:08 AM
Re: Please help me achieve Streamlined Counting
>but how would I get the output in hexadecimal?
A real shell will allow you to print in hex with:
$ typeset -i16 CURRENT=20; echo $CURRENT
16#14
- Tags:
- hex