Find the answer to your Linux question:
Results 1 to 7 of 7
Hi, Can someone please help me or clarify on the following 2 questions: 1) How to find how many no. of open files are currently open in a Linux/Unix box ...
  1. #1
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Red face 2 questions: $0 $1, How to count no.of Open files per user

    Hi,

    Can someone please help me or clarify on the following 2 questions:

    1) How to find how many no. of open files are currently open in a Linux/Unix box per user (user wise list sorted acc. to the highest no. of count of open files).

    2) Let's suppose script "sangal_ak04.sh" contains:
    echo $0 - $1

    See below:
    ========
    (1) /tunna/tunna/takk/takk/tunna/aksutil
    [chunna_ali@musalli] $ cat >sangal_ak04.sh
    echo $0 - $1
    (1) /tunna/tunna/takk/takk/tunna/aksutil
    [chunna_ali@musalli] $ chmod 777 sangal_ak04.sh

    (1) /tunna/tunna/takk/takk/tunna/aksutil
    [chunna_ali@musalli] $ ./sangal_ak04.sh 1
    ./sangal_ak04.sh - 1

    (1) /tunna/tunna/takk/takk/tunna/aksutil
    [chunna_ali@musalli] $ ./sangal_ak04.sh
    ./sangal_ak04.sh -

    (1) /tunna/tunna/takk/takk/tunna/aksutil
    [chunna_ali@musalli] $ . ./sangal_ak04.sh
    -bash -

    (1) /tunna/tunna/takk/takk/tunna/aksutil
    [chunna_ali@musalli] $


    Then what value should I use (while running this script in Parent shell) to print the value of my scriptname. i.e. I want to print ./sangal_ak04.sh using shell parameter variables....i.e. $0, 1 2 3 etc..


    Any helps!
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Quote Originally Posted by Sangal-Arun
    1) How to find how many no. of open files are currently open in a Linux/Unix box per user (user wise list sorted acc. to the highest no. of count of open files).
    # lsof -u user_name

    That will show open files for user_name. See the manpages for lsof( 8 ) for more info.

    You may want to create an iterative loop that will run that command for each user currently logged into the system, and then sort per your specifications. Good exercise for you.

    2) Let's suppose script "sangal_ak04.sh" contains:
    echo $0 - $1...
    I can barely make any sense out of this question. If you're looking to display the name of the currently running script, as invoked, that is done by:
    echo $0

    If you want just the script name (and no path), use:
    echo $( basename $0 )

  3. #3
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101
    Yep, but RH4 doesn't have lsof. Is there any other way?

    For the 2nd ?, I want to print the scriptname and in the parent shell. Let me know what variable should I use.

    $ cat ./sangal_ak04.sh
    echo $0 - $1 - $( basename $0 )

    $ . ./sangal_ak04.sh
    -bash - - -bash

    here in the above example, I want to pring ./sangal_ak04.sh using shell variable, let me know how to achieve that.

    $ ./sangal_ak04.sh 1
    ./sangal_ak04.sh - 1 - sangal_ak04.sh

    $ ./sangal_ak04.sh
    ./sangal_ak04.sh - - sangal_ak04.sh
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  4. #4
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Quote Originally Posted by Sangal-Arun
    Yep, but RH4 doesn't have lsof. Is there any other way?
    Yes. Install lsof using your package manager.

    here in the above example, I want to pring ./sangal_ak04.sh using shell variable, let me know how to achieve that.
    Why are you sourcing in the script? Run it instead: ./script_here. (In other words, stop sourcing it in with the dot (.) operator.)

    I already showed you how to do this in my example. The variable is $0.

  5. #5
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    P.S. If there's a reason you need to print the script name after sourcing it in, then explain that. At the moment it looks like a pointless/redundant exercise, and there may be a better approach I can suggest, depending on what you're trying to do.

  6. #6
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101
    Let's suppose I have a script: main.sh
    It calls few other scripts menu1.sh, menu2.sh and menu3.sh

    #!/bin/bash

    . ~tora_tora/Jhola_Linux/menu1.sh
    disp <some value to pass here>
    . ~tora_tora/Jhola_Linux/menu2.sh aks sangal
    disp <some value to pass here>
    . ~tora_tora/Jhola_Linux/menu3.sh 1 2 3 KGP
    disp <some value to pass here>
    . ~tora_tora/Jhola_Linux/menu4.sh TAKK TAKK TUNNA picture.jpg
    disp <some value to pass here>


    ...
    ....more shell code....
    ....

    #End of script.

    Disp is a funtion, which will tell the "NAME of the script" which has just been called before.
    Now, what I have to pass in place of disp "<some value to pass here>" so that it can show at the output that my main.sh script has called menu[1234].sh scripts one by one.

    NOTE:
    1) I want a flexible code i.e. don't want to hardcode the names of the script i.e. echo "menu1.sh called..in parent shell" , echo "now menu2.sh has been called...", .... etc. etc. In future if someone changes or add more scripts, disp function should show the name of the script which has just been called irrespective of hard coding the name of the script which is mentioned inside main.sh

    2) Menu1.sh, Menu2.sh,...etc script can have arguments also.

    LPDS
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  7. #7
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Just to take a step back for a moment, do you understand what the dot (.) operator does? Do you really need to be sourcing those scripts in (to capture some environment variables perhaps..?) or would it be sufficient to just run them? From your earlier posts, it sounds like running them instead of sourcing them in would solve your problem.

Posting Permissions

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