- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script for total files size
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
Discussions
Discussions
Forums
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
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
тАО10-04-2009 03:30 AM
тАО10-04-2009 03:30 AM
Hi Admins,
I want to get the total size of files dated Oct 4 under /data.Find the script which i tried.
#!/usr/bin/sh
total=0
files=du -sk `ls -lrt /data | grep "Oct 4"|awk '{print $9}'`
for filesize in $files
do
total=$total+$files
done
But m ended up with error.
./test[3]: -sk: not found.
Plz suggest on this.
regards
himacs
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2009 03:51 AM
тАО10-04-2009 03:51 AM
Re: script for total files size
http://docs.hp.com/en/B2355-90046/index.html
why are you using du ?
du will show you disk usage. *not* file size - these are not the same thing...
if you really want to gather disk sizes in this rather crude way, I guess:
#!/usr/bin/sh
total=0
sizes=`ls -lrt /data | grep "Oct 4"|awk '{print $5}'`
for filesize in $sizes
do
(( total = $total + $filesize ))
done
echo $total
might work for you (untested)
HTH
Duncan
I am an HPE Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2009 03:55 AM
тАО10-04-2009 03:55 AM
Re: script for total files size
> if you really want to gather disk sizes
should of course read:
if you really want to gather and total file sizes
HTH
Duncan
I am an HPE Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2009 03:58 AM
тАО10-04-2009 03:58 AM
Re: script for total files size
The above line is equivalent to:
files=du
-sk `ls -lrt /data | grep "Oct 4"|awk '{print $9}'`
The $files variable got assigned the string "du" and then the system attempted to execute a command named -sk, which of course did not exist.
You would need to use multiple sets of backquotes, which gets confusing and is prone to errors. Fortunately, there is another way: you can use $( ... ) instead of `...`. That is easier to cascade:
files=$(du -sk $(ls -lrt /data | grep "Oct 4"|awk '{print $9}'))
Your script still has some limitations:
1.) If there are more files created on Oct 4 than can fit on a single command line (run "getconf ARG_MAX" to see the maximum command line length in bytes), your script will fail. But if you already know that the amount of files is relatively small, that is not important.
2.) If there are sub-directories under /data which have been changed on Oct 4, this may skew your results. If there are no subdirectories, not a problem.
3.) The script calculates files dated Oct 4, but Oct 4 _of which year_? If you're sure all files are less than 1 year old, this should not be a problem.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2009 03:59 AM
тАО10-04-2009 03:59 AM
Re: script for total files size
files=$(du -sk $(ls -lrt /data | grep "Oct *4" | awk '{print $9}'))
I'm not sure why you are using du(1) then totaling. Are you worried about sparse files?
total=$(ll /data | awk '
BEGIN { total = 0 }
{ total += $5 }
END { printf "%1.0f\n", total }')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2009 04:07 AM
тАО10-04-2009 04:07 AM
Re: script for total files size
files=du
-sk `ls -lrt /data | grep "Oct 4"|awk '{print $9}'`
Almost, they are on the same line.
>You would need to use multiple sets of backquotes, which gets confusing and is prone to errors.
I'm not aware of any way to nest ``, so perhaps the correct statement is "impossible"?
(You could split them in multiple steps.)
Oops, I lost that "Oct 4" step:
total=$(ll /data | awk /Oct *4/ '
BEGIN { total = 0 }
{ total += $5 }
END { printf "%1.0f\n", total }')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2009 04:54 AM
тАО10-04-2009 04:54 AM
Re: script for total files size
Thanx for the replies.Since m new into scripting world, i have limited knowledge on that.
So Denis, before testing what u suggested i need to refer that commands.
And Duccan ,Thanx for the document.
And below script i modified.But below error.
#!/usr/bin/sh
files=`ls -lrt /data | grep "Oct 4"|awk '{print $9}'`
size=`du -sk $files`
total=0
for i in $size
do
total=$total+$size
done
echo $total
du: FCT_LOANS_CONTRACTS_20091001.DAT.gz: No such file or directory
du: FCT_ICCF_DETAILS_20091001.DAT.gz: No such file or directory
du: FCT_INSTRUMENT_TXN_20091001.DAT.gz: No such file or directory
du: FCT_DISBURSEMENT_20091001.DAT.gz: No such file or directory
du: DIM_PDC_20091001.DAT.gz: No such file or directory
du: DIM_PERIOD_CODE_STATUS_20091001.DAT.gz: No such file or directory
du: FCT_ALL_AC_ENTRIES_20091001.DAT.gz: No such file or directory
du: DIM_MIS_DATES_20091001.DAT.gz: No such file or directory
du: FCT_LOAN_CONTRACT_LINKAGES_20091001.DAT.gz: No such file or directory
du: FCT_LIMIT_UTIL_20091001.DAT.gz: No such file or directory
du: DIM_MIS_20091001.DAT.gz: No such file or directory
du: FCT_LIMITS_20091001.DAT.gz: No such file or directory
du: DIM_MARKET_20091001.DAT.gz: No such file or directory
du: FCT_LC_INFO_PARTIES_20091001.DAT.gz: No such file or directory
du: FCT_LCS_CONTRACTS_20091001.DAT.gz: No such file or directory
I know you suggested not to use du -sk command.But when i tested the command in shell prompt i got desired output.
#du -sk `ls -lrt|grep "Oct 2"|awk '{print $9}'`
353 FCT_VEHICLE_DETAILS_20091001.DAT.gz
109 FCT_CONTRACT_STATUS_20091001.DAT.gz
4090 FCT_CONTRACT_MIS_20091001.DAT.gz
572 FCT_GL_ACCBREAKUP_20091001.DAT.gz
5243 DIM_CUSTOMER_20091001.DAT.gz
14426 FCT_ADV_SCHEDULE_20091001.DAT.gz
798 FCT_LOANS_CONTRACTS_20091001.DAT.gz
702 FCT_ICCF_DETAILS_20091001.DAT.gz
570 FCT_INSTRUMENT_TXN_20091001.DAT.gz
38 FCT_DISBURSEMENT_20091001.DAT.gz
Plz suggest on this
regards
himacs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2009 05:20 AM
тАО10-04-2009 05:20 AM
Solutionsize=`du -sk $files`
This fails because you are looking at /data but the awk is only getting the filenames, so the du(1) fails.
You'll need to cd to /data, or change to use:
size_files=$(du -sk $(ls -lrt /data | grep "Oct *4" | awk '{print "/data/" $9}'))
>when I tested the command in shell prompt I got desired output.
Because you were in /data/.
>353 FCT_VEHICLE_DETAILS_20091001.DAT.gz
And you will have to extract field 1 from this to do the summation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2009 07:15 AM
тАО10-04-2009 07:15 AM
Re: script for total files size
Thanx for ur time.
Below is the script i written which given correct output.
#!/usr/bin/sh
files=`ls -lrt /data | grep "Oct 2"|awk '{print "/data/" $9}'`
total=0
for i in $files
do
var1=`du -sk $i|awk '{print $1}'`
#echo $var1
total=`expr $total + $var1`
done
echo $total
It will work ,if no sub folders exists
Please tell me how to modify the same if subfolder exists
regards
himacs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-04-2009 07:28 AM
тАО10-04-2009 07:28 AM
Re: script for total files size
> Please tell me how to modify the same if subfolder exists
To accommodate this it is easiest to use 'find -type f' to recursively descend subordinate directories below the starting path.
One way to limit what you have to the date of October 4 is to do:
# touch -amt 200910040000 /tmp/ref1
# touch -amt 200910042359 /tmp/ref2
# find /path -type f \( -newer /tmp/ref1 -a ! -newer /tmp/ref2 \)
This would find only files that have been modified during the 24-hour period of October 4th. You should read the manpages for 'touch' and for 'find' for a better understanding.
If you don't want to use 'find()' you could use 'ls' recursively (with its '-R' option). In that case, though, you will have to filter out only files by examining the first character of a long output. Hint: directories begin with "d" and regular files with "-".
Regards!
...JRF...