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 ...
- 11-16-2007 #1
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!
- 11-16-2007 #2# lsof -u user_name
Originally Posted by Sangal-Arun
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.
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:2) Let's suppose script "sangal_ak04.sh" contains:
echo $0 - $1...
echo $0
If you want just the script name (and no path), use:
echo $( basename $0 )
- 11-16-2007 #3
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
- 11-16-2007 #4Yes. Install lsof using your package manager.
Originally Posted by Sangal-Arun
Why are you sourcing in the script? Run it instead: ./script_here. (In other words, stop sourcing it in with the dot (.) operator.)here in the above example, I want to pring ./sangal_ak04.sh using shell variable, let me know how to achieve that.
I already showed you how to do this in my example. The variable is $0.
- 11-16-2007 #5
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.
- 11-16-2007 #6
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
- 11-18-2007 #7
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.


Reply With Quote