Visit Our UNIX and Linux User Community


Function SUM SIZE


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Function SUM SIZE
# 1  
Old 07-29-2009
Function SUM SIZE

Dear Friends,

I wrote a script that get the size of specific files in a specific space directory. To get the total size I wrote a function in that script.
So far I am not convinced that function is working correctly.

Do you mind tell if there is anything wrong.

I am on SOLARIS (KSH)
The default size of the files are on Ko

PHP Code:
 #------------------------------------------------------
sum_taille () {

   
size_koctet=$1
   
if [ $size_koctet -gt 1073741824 ]
   
then
      
((size=$size_koctet /1024 /1024 /1024))
       
unite="Tera"
   
else 
    if [ 
$size_koctet -gt 1048576 ]
       
then
          
((size=$size_koctet /1024 /1024))
          
unite="Go"
    
else
        if  [ 
$size_koctet -gt 1024 ]
        
then
        
((size=$size_koctet /1024))
              
unite="Mo"
        
fi
       fi
   fi
   
echo "$size $unite"
}
#------------------------------------------------------ 
Thanks in advanced for your help
# 2  
Old 07-29-2009
this may help
Code:
du -hc file1 file2 ...

# 3  
Old 07-29-2009
Function SUM SIZE

Dear johnbach,

This cannot help me as all files listed are not on the same directory, and I am talking about more than 10.000 files.

Thanks anyway for your help
# 4  
Old 07-29-2009
Code:
fns()
{
arr[0]=KB
arr[1]=MB
arr[2]="GB"
arr[3]="TB"

   sz=$1
   ctr=0;
   while [ sz -gt 1023 ]
      do
         ((sz=$sz /1024.0))
         ((ctr=$ctr +1))
      done
   echo "Size="$sz" "${arr[$ctr]};
}
fns $1

# 5  
Old 07-31-2009
Function SUM SIZE - SOLVED

Dear johnbach,

I just wanted to say thank you for your help. The function is working fine..


Thanks again Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #110
Difficulty: Easy
As of 2014, Apple's macOS was the largest Unix installed base globally.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sum function

I have file input China,Gaolian,9135774346294,AirAsia,0,0,0,0,0,0,0,0,0,0,0,0,0,0,165 India,Gangga,9135770291502,AirAsia,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3325 India,Nahdit,9135766545904,AirAsia,0,0,0,0,0,0,0,0,0,0,0,0,0,0,440 India,Kathman,9135768476591,AirAsia,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0... (5 Replies)
Discussion started by: radius
5 Replies

2. Shell Programming and Scripting

Script - SUM SIZE

Hello, I need help. I working a a script that will get back directory size. I am on linux. I am using du -sk to get the size of directories. But, as the script is launch under nagios, i need to find a work aound to get rid of time out issue due to the large amount of files in one of... (1 Reply)
Discussion started by: Aswex
1 Replies

3. UNIX for Dummies Questions & Answers

How to get the set of files size as a sum in a directory.

Hi, Can someone help me to get the complete files size (sum) over a perod time (1 day,2days)in a directory. eg: Directory :ABC I have a1,a2,a3 files are created in last 24 hours so I need to get the some of all these files. I am using the below find command but its giving me the... (1 Reply)
Discussion started by: gaddamja
1 Replies

4. Shell Programming and Scripting

perl Image::size function

Hi, How to use Image::size function ? because I want to list all image thatare less than size pixels in horizontal resolution. so here is my code : #!/usr/bin/perl -w use Image::Size; use constant GIVEN_WIDTH = '100'; my @filtered_images = grep { my @d = imgsize( $_ ); $d < GIVEN_WIDTH }... (8 Replies)
Discussion started by: guidely
8 Replies

5. Shell Programming and Scripting

[SOLVED] Awk one line to sum up a function

I need help with debugging an error in my awk script. I have a shell script with variable named U_new_i and want to pass it to awk for use in a summation. The original file have the following content. cat test.txt -2445.7132000000 -2444.9349000000 -2444.3295000000 -2443.1814000000 ... (0 Replies)
Discussion started by: Quantum_Dot
0 Replies

6. UNIX for Advanced & Expert Users

size for sum variable limitation on awk

Hello first, truth been told, I'm not even close to be advanced user. I'm posting here because maybe my question is complicated enough to need your expert help I need to use awk (or nawk - I don't have gawk) to validate some files by computing the total sum for a large numeric variable. It... (1 Reply)
Discussion started by: cwitarsa
1 Replies

7. Shell Programming and Scripting

Sum of file size in directory / subdirectory

Hi , I am trying to write something to find the size of particular type of files in a directory & it's subdirectory and sum the size .. These types of file are found at directory level or its subdirectories level .. #!/bin/ksh FNAME='.pdf' S_PATH=/abc/def/xyz find $S_PATH -exec ls -lad... (4 Replies)
Discussion started by: Vaddadi
4 Replies

8. Solaris

calculate sum size of files by date (arg list too long)

Hi, I wanted a script to find sum of files for a particular date, below is my script ls -lrt *.req | nawk '$6 == "Aug"' | nawk '$7 == "1"'| awk '{sum = sum + $5} END {print sum}' However, i get the error below /usr/bin/ls: arg list too long How do i fix that. Many thanks before. (2 Replies)
Discussion started by: beginningDBA
2 Replies

9. Shell Programming and Scripting

How to traverse directory structure and sum size of files?

How do I write a bash or ruby or perl or groovy script to print all the files in my directory tree that are one-to-two years old, the size of each file, and the sum of file sizes and then delete them? I was using find . -atime +365 -exec rm '{}' \; but the problem was that I could not... (5 Replies)
Discussion started by: siegfried
5 Replies

10. Shell Programming and Scripting

Sum up files whose size Kbytes and Mbytes

Hello Friends, When i type du -sh *.jar | sort -n under a library directory i get a result similar below output: 1M 1.jar 2.4M 2.jar 4.5M 3.jar . . . . . . 1K (n-2).jar 15K (n-1).jar 77.7K n.jar I want to sum up the size... (1 Reply)
Discussion started by: EAGL€
1 Replies

Featured Tech Videos