- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script error in du
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-01-2002 08:58 PM
06-01-2002 08:58 PM
#cat du.txt
/home
/etc
/sbin
...
I would like to write a script to calculate the disk usage of these filesystems. I did it as follows:
#cat du.sh
#!/bin/sh
for i in `cat du.txt`
do
$all+=du $i
done
echo $all
The shell complained of an undefined variable $all. Purpose of $all is to have a grand total of the entire disk usage of the filesystems specified in du.txt.
Could someone help please help out? Please feel free to also comment on other more efficient ways of performing the same task.
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2002 09:25 PM
06-01-2002 09:25 PM
SolutionI would use the following
You have your files in /tmp/calc
/home
/usr
Then have script calc1
#!/usr/bin/sh
calc=/tmp/calc
for file in $(cat $calc)
do
du -sk $file | awk '{ print $1 }' >> /tmp/calc2
done
cat /tmp/calc2 | awk 'BEGIN {total=0;} {total=total+$1;} END {print total,"\n";}
' > /tmp/calc3
Regards
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2002 09:26 PM
06-01-2002 09:26 PM
Re: Script error in du
#!/bin/sh
tot=0
for i in `cat du.txt`
do
((tot=$tot+`du -sk $i|awk '{print $1}'`))
done
echo $tot
You would want to use "du -sk /dirname" so that you get the total of that whole dir in KBytes. Do ..
# man du
for details..
The "awk" statement after the "du" will extract first field .. example
# du -sk /etc
95456 /etc
hope it helps..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2002 09:27 PM
06-01-2002 09:27 PM
Re: Script error in du
#!/bin/sh
tot=0
for i in `cat du.txt`
do
((tot=$tot+`du -sk $i|awk '{print $1}'`))
done
echo $tot
You would want to use "du -sk /dirname" so that you get the total of that whole dir in KBytes. Do ..
# man du
for details..
The "awk" statement after the "du" will extract first field .. example
# du -sk /etc
95456 /etc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2002 09:28 PM
06-01-2002 09:28 PM
Re: Script error in du
I would use the following
You have your files in /tmp/calc
/home
/usr
Then have script calc1
#!/usr/bin/sh
calc=/tmp/calc
for file in $(cat $calc)
do
du -sk $file | awk '{ print $1 }' >> /tmp/calc2
done
cat /tmp/calc2 | awk 'BEGIN {total=0;} {total=total+$1;} END {print total,"\n";}
' > /tmp/calc3
Regards
Steve