basename problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting basename problem
# 8  
Old 04-09-2009
Code:
 #!/bin/sh


    fnGetUserQuota ()
    {
        #Below is a variable declaring the threshold limit for the quota

        limit=24

        #prints quota's on all file systems then greps the line with /home
        # The $2 is the usage and %3 is the quota. The calculation results in
        # the amount of quota being used. This is all stored in the variable 'q'

        QuotaResult=`quota -v | grep '^/home' | awk '{print int($2/$3*100)}'`
   }
   
   fnTestQuota ()
   {
        #The if statement tests if QuotaResult is more then the threshold limit
        #If its greater consider reducing your usage otherwise just prints current
        # usage

        #start of test statement

        if  [  $QuotaResult  -gt  $limit  ] 
        then
            echo "you are currently using  $QuotaResult %  of your quota "
            echo "consider reducing your usage"
            return 0        
        else
            echo "you are currently using $QuotaResult of your quota"
            exit 0

        fi
    
        #end of test statement
    }

    fnListDirectories ()
    {
        count_num=10
        blank_white=echo""
a=`ls -1 -d /home/j/jdongs/*/|while read line; do basename "$line";done`
        $blank_white
        echo "The 10 biggest directories in your home directory are:"
        

        echo "Size    Directory"
        echo "----    ---------"

        #The following prints the largest to smallest directories sorts them
        # numerically in reverse but only lists the first 10 in kilobytes
        # in a human readable format
        
        $blank_white
      
        du -k -h $a | sort -nr | head -$count_num
    }

    fnGetUserQuota
    fnTestQuota
    fnListDirectories

    exit 0

# 9  
Old 04-10-2009
Ok, maybe You have directories with names including spaces?
Try to include this for debugging before the du command:

echo This is a:
for x in $a;do echo $x;done
echo This is ls output:
ls -1 -d /home/j/jdongs/*/|while read line; do basename "$line";done

To see if they give similar output.
/L

PS Btw, have You tried using just

du -k $dirname |sort -nr

etc...
It will list the directories for You?

/L

Last edited by Lakris; 04-10-2009 at 07:11 AM.. Reason: alternative example
# 10  
Old 04-10-2009
ok ill try it now and ill let you know what i get thanks for assisting
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Pipe to basename

I would like to use basename with wc .. I know I can use awk, but want to use basename. Change this wc -l txt* 106 /home/popeye/txt1 154 /home/popeye/txt2 159 /home/popeye/txt3 420 total to this wc -l txt* 106 txt1 154 txt2 159 txt3 420 total (4 Replies)
Discussion started by: popeye
4 Replies

2. Shell Programming and Scripting

$(basename $0)

what is the meaning of "script_name=$(basename $0)", can someone please explain? (1 Reply)
Discussion started by: abhi200389
1 Replies

3. Shell Programming and Scripting

Basename in subshell

Hi All, I would like to improve my bash scripting skill and found a problem which I do not understand. Task is to search and print files in directory (and subdirecories) which contains its own name. Files can have spaces in name. This one works fine for files in main directory, but not for... (4 Replies)
Discussion started by: new_item
4 Replies

4. UNIX for Dummies Questions & Answers

awk and basename

im trying to extract the basename of a process running on a host processx is running at host1 as /applications/myapps/bin/processx i wanted to check if its running, then extract the basename only using: $ ssh host1 "ps aux | grep -v 'grep' | grep 'processx'" | awk '{ print basename $11}' ... (10 Replies)
Discussion started by: kaboink
10 Replies

5. Shell Programming and Scripting

Difference between $0 and basename

Hi, Could you please help me to know the difference between $0 and basename in unix how they useful in shell scripting. Thanks in advance (3 Replies)
Discussion started by: lnviyyapu
3 Replies

6. Shell Programming and Scripting

Need help with basename command

I have a file fileinput.txt: File home/me/fileA.doc is size 232 File home/you/you/fileB.doc is size 343 File /directory/fileC.doc is size 433 File /directory/filed.doc cannot find file size I want to use the basename command (or any other command) to output: File fileA.doc is... (3 Replies)
Discussion started by: linuxkid
3 Replies

7. UNIX for Dummies Questions & Answers

basename

Hi, can anyone let me know how to interpret the below third line in the following code. Gone through the man pages of "basename", but no go. for f in *.foo; do base=`basename $f .foo` mv $f $base.bar done Thanks. (2 Replies)
Discussion started by: venkatesht
2 Replies

8. Shell Programming and Scripting

basename $0

hi, can anyone help me by saying what is basename.. i have seen this in many programs where the basename is used.... thanks, Krips (4 Replies)
Discussion started by: kripssmart
4 Replies

9. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

10. Shell Programming and Scripting

reverse of basename

Hi, Can someone let me know how to find the reverse of the basename i.e i have /apps/tiv/pmon/xxxx.dat and I want /apps/tiv/pmon/ Thanks (7 Replies)
Discussion started by: braindrain
7 Replies
Login or Register to Ask a Question