- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Writing a Script: du -k
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
08-10-2004 07:16 PM
08-10-2004 07:16 PM
Writing a Script: du -k
Please helpme out in writing a script for the below scenario:
I have /Home directory under which i have all the User's Home directory as shown below. I have to write a script which should generate an output showing User Home Directory, Disk Space Used in KB, % Disk Space Used in descending order.
bdf command ouput for /Home:
/vol/vol1/home/tatc-in 73400320 63090040 10310280 86% /tmp_mnt/home/
Directories under /Home:
cmuluktl d03013 d03019 mappukut sprashan
DEL1.KAL d03001 d03014 d03020 mprakash sramanat
FINAL d03004 d03015 d03021 report_disk twr16
USftp d03005 d03016 d03023 sdhondi twr17
anandam d03009 d03017 indiaftp skondapa vbojja
apemmara d03010 d03018 kkomati smasabat
Thanks,
Sai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 07:28 PM
08-10-2004 07:28 PM
Re: Writing a Script: du -k
# du -k | sort -k 1,1
This works for me.
for e.g.
# pwd
/home
# du -k
0 ./lost+found
8 ./one
8 ./two
16 .
# du -k | sort -k 1,1
0 ./lost+found
16 .
8 ./one
8 ./two
# ls -al
total 16
drwxr-xr-x 5 root root 96 Aug 11 12:54 .
drwxr-xr-x 15 root root 8192 Aug 10 19:02 ..
drwxr-xr-x 2 root root 96 Aug 9 18:12 lost+found
drwxrwxrwx 2 root sys 96 Aug 11 12:54 one
drwxrwxrwx 2 root sys 96 Aug 11 12:54 two
#
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 07:50 PM
08-10-2004 07:50 PM
Re: Writing a Script: du -k
Try this script:
#!/sbin/sh
OUTPUT=" Kb Directory"
DIRS=`ll|grep ^d|awk '{ print $9}'`
for DIR in $DIRS
do
OUTPUT="$OUTPUT\n`du -ks $DIR`"
done
echo "$OUTPUT"|sort -n
Rgds,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 07:53 PM
08-10-2004 07:53 PM
Re: Writing a Script: du -k
sorry for that.. little confusion...
This should work.
# du -k | sort -k 1n,1
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 07:54 PM
08-10-2004 07:54 PM
Re: Writing a Script: du -k
See ernesto's here:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=51050
and Ben Sachs
http://forums1.itrc.hp.com/service/forums/parseCurl.do?CURL=%2Fcm%2FQuestionAnswer%2F1%2C%2C0x836cc1c4ceddd61190050090279cd0f9%2C00.html&admit=716493758+1092210687681+28353475
There is a gold mone of scripts in the 3 threads.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 08:52 PM
08-10-2004 08:52 PM
Re: Writing a Script: du -k
Here's a handy one:
rm /tmp/du_dir_list 2>/dev/null
rm /tmp/du_dir_list2 2>/dev/null
echo " "
echo "FILES:"
echo " "
ll | grep -v ^d |sort -k 5n
ll | grep ^d |cut -c59- > /tmp/du_dir_list
if [ -s /tmp/du_dir_list ]
then
echo " "
echo "DIRECTORIES (in Kb):"
echo " "
for dirname in `cat /tmp/du_dir_list`
do
du -sk $dirname | awk '{ printf("%8d %s\n",$1,$2) }' >>/tmp/du_dir_list2
done
sort /tmp/du_dir_list2
else
echo " "
echo "There are no Directories:"
echo " "
fi
rm /tmp/du_dir_list 2>/dev/null
rm /tmp/du_dir_list2 2>/dev/null
echo " "
bdf .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 09:22 PM
08-10-2004 09:22 PM
Re: Writing a Script: du -k
du -k|sort -k1,1nr
The nr specifies numerical reverse (default is smallest first)
Mark Syder (like the drink but spelt different)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 09:28 PM
08-10-2004 09:28 PM
Re: Writing a Script: du -k
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 09:50 PM
08-10-2004 09:50 PM
Re: Writing a Script: du -k
#!/usr/bin/ksh
for user in `ls /home`; do
fssize=`bdf /home | grep -v "^Filesystem" | awk '{ print $2 }'`
homesize=`du -ks /home/$user | grep -v "^Filesystem" | awk '{ print $1 }'`
if [[ $homesize -ne 0 ]]
then
per=$(echo "$homesize $fssize" | awk '{ print $1/$2*100 }')
else
per=0
fi
home=`du -ks /home/$user | awk '{ print $2 }'`
echo "$home $homesize $fssize $per %"
done >> /tmp/form.log
echo "HOME DIRECTORY USAGE DISK SPAGE %DISK SPACE USAGE"
cat /tmp/form.log | sort -r -k 4
rm -f /tmp/form.log
## end ###
Output:
=======
# ksh /tmp/form.ksh
HOME DIRECTORY USAGE DISK SPAGE %DISK SPACE USAGE
/home/muthu 3152 32768 9.61914 %
/home/testusr 32 32768 0.0976562 %
Regards
Muthu