Find the answer to your Linux question:
Results 1 to 5 of 5
I have try by this code Code: echo "" > outputISP echo "" > outputISP2 foreach priod ( 720 580 360 270 120 90 ) foreach priod2 ( 580 360 ...
  1. #1
    Just Joined!
    Join Date
    Jul 2007
    Posts
    31

    Question how canI subtact two number that have been calculated by foreach? I try but it hang?!

    I have try by this code

    Code:
    echo "" > outputISP 
    echo "" > outputISP2
        
    foreach priod ( 720 580 360 270 120 90 )
     foreach priod2 ( 580 360 270 120 90  0)
              
    set fsize = `find  -mtime -${priod} -type f | xargs ls -tg | awk '{ size += $4 } END {print size}' `
    set fsize2 = `find  -mtime -${priod2} -type f | xargs ls -tg | awk '{ size2 += $4 } END {print size2}' `
    set defsize = `awk '{ defsize = fsize - fsize2 } END {print defsize}' `
    	  
    echo "  ${priod}  ${fsize}" >> outputISP
    echo "  ${priod2}  ${defsize}" >> outputISP2
    end
    end	  
    	  
    more outputISP2
    but it hang

    I wont to calculate "fsize" each of "priod" and calculate "fsize2"of each "priod2"
    and subtract sequentially each result of "fsize" - "fsize2"
    for example first number of "priod" is 720 and first number of "priod2" is 580 and
    calculate size of 720 =900000 and size of 580=800000
    the result should be 900000 - 800000=100000

    by the way “fsize” and fsize2 calculate the Data size growth of file from number period witch is "priod" and "priod2"

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    alivip,

    Please post your code in code tags and try to spell, punctuate, and capitalize correctly to improve readability.

    Regards

  3. #3
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Ok, I think this line isn't proper:

    Code:
    set defsize = `awk '{ defsize = fsize - fsize2 } END {print defsize}'`
    I'm not familiar with csh but I think your loop should look like this:

    Code:
    foreach priod ( 720 580 360 270 120 90 )
      foreach priod2 ( 580 360 270 120 90 0)
        set fsize = `find -mtime -${priod} -type f | xargs ls -tg | awk '{ size += $4 } END {print size}'`
        set fsize2 = `find -mtime -${priod2} -type f | xargs ls -tg | awk '{ size2 += $4 } END {print size2}'`
        set defsize = $fsize - $fsize2
        echo " ${priod} ${fsize}" >> outputISP
        echo " ${priod2} ${defsize}" >> outputISP2
      end
    end
    Regards

  4. #4
    Just Joined!
    Join Date
    Jul 2007
    Posts
    31

    it does not solve the problem

    it does not solve the problem
    it hang same as before

  5. #5
    Just Joined!
    Join Date
    Jul 2007
    Posts
    31

    I do this modification it work but not proberly

    I do this modification
    Code:
     
    set index = 1
        set limit = `expr $#values - 1`
        while ($index <= $limit)
    	set value = $values[$index]
    	echo $value
    	
    	# calculate the size of files within a specific period:
    	set fsize = `find  -mtime -$value -type f | xargs ls -tg | awk '{ size += $4 } END {print size}'`
            
    	# for testing:
    	echo $fsize
    	
    	# calculate the next index:
    	set nextIndex = `expr $index + 1`
    	
    	set value = $values[$nextIndex]
    	echo $value
    	
    	# calculate the size of files within the next specific period:
    	set fsize2 = `find  -mtime -$value -type f | xargs ls -tg | awk '{ size2 += $4 } END {print size2}' `
    	
    	# for testing:
    	echo $fsize2
    	
    	# calculate the difference:
    	set defsize = `expr $fsize - $fsize2`
    	
    	# for testing:
    	echo defrance
    	
    	# for testing:
    	echo $defsize
    	
    	# write into file:
    	echo "  $values[$index]  ${defsize}" >> outputISP2
    	
    	# update index:
    	set index = `expr $nextIndex`
    	
    	echo "------------------------------"
    	echo $index
    	echo "------------------------------"
        end

    give the result correct but for just 2 of 6 of array (720 ,580 ) but the other give dash "-"

    and error message
    "xargs: unmatched single quote"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...