- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script help....expr command
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
06-05-2009 03:30 AM
06-05-2009 03:30 AM
Script help....expr command
#!/usr/bin/sh
#
#echo "Which volume group? \c"
#read ANS
HOMEDIR=/home/smid/scripts
BDFMEGS=$HOMEDIR/bdfm
if [ ! -x $BDFMEGS ]
then
echo "ERROR: $BDFMEGS does not exist!"
exit 1
fi
SUM=0
# Cut out the first line from output
for i in `/usr/local/bin/sudo strings /etc/lvmtab |grep dev|grep -v dsk|grep -v vg00`; do
var=`$BDFMEGS|grep $i | grep -v : |awk '{print $3}'`
SUM=`expr $SUM + $var`
echo "`hostname`: $i Total Space Used (MB) = $SUM"
done
I am almost there but the expr is not working out. Here is what I get for the output when using set -x:
$ ./disk_used.sh
+ HOMEDIR=/home/smid/scripts
+ BDFMEGS=/home/smid/scripts/bdfm
+ [ ! -x /home/smid/scripts/bdfm ]
+ SUM=0
+ /usr/local/bin/sudo strings /etc/lvmtab
+ grep dev
+ grep -v vg00
+ grep -v dsk
+ + /home/smid/scripts/bdfm
+ grep /dev/vgvnadmin
+ grep -v :
+ awk {print $3}
var=5886
394
332
7382
6854
9099
29
+ + expr 0 + 5886 394 332 7382 6854 9099 29
expr: Syntax error
So it isn't using +'s between each $var.
Thanks for the help,
S
- Tags:
- expr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2009 03:56 AM
06-05-2009 03:56 AM
Re: Script help....expr command
Try this instead
>>SUM=`expr $SUM + $var`
SUM= $((SUM + var))
Rgds
Johnson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2009 04:12 AM
06-05-2009 04:12 AM
Re: Script help....expr command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2009 04:19 AM
06-05-2009 04:19 AM
Re: Script help....expr command
The syntax of the 'expr' statement is OK. Your trace suggests that your 'var' variable isn't a simple integer but some string of integers. Consider:
# cat ./mybad
#!/usr/bin/sh
set -x
SUM=0
for var in "1 2 3 4 5"
do
SUM=`expr $SUM + $var`
echo $SUM
done
# ./mybad
+ SUM=0
+ + expr 0 + 1 2 3 4 5
expr: Syntax error
SUM=
+ echo
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2009 04:34 AM
06-05-2009 04:34 AM
Re: Script help....expr command
This: SUM=`expr $SUM + $var`
can be done as: (( SUM += var ))