LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   shell -top- like program (https://www.linuxquestions.org/questions/programming-9/shell-top-like-program-532533/)

Filipe 02-26-2007 07:57 AM

shell -top- like program
 
I would like to write a program to
display some variable info in shell
like "top" program refreshing automaticly

where can i view infos and simple examples
to achieve this ?

Thank you very much.

matthewg42 02-26-2007 08:04 AM

You can make a little while loop which will execute some command (e.g. echoing the values of some shell variables), and then sleep for a few seconds before looping:
Code:

SLEEPTIME=3
while true; do
    ...
    sleep $SLEEPTIME
done


Filipe 02-26-2007 08:09 AM

like "top" program...

matthewg42 02-26-2007 08:42 AM

Top is a process and system resource monitor, so something which monitors shell variables is not really "like" top.

Please be more clear what you require.

Assuming the permissions allow it and the proc filesystem is available on the system you are using, you can investigate the environment of another process using the /proc/[PID]/environ special file. Note that this does not include all shell variables - only those exported to the environment.

Filipe 02-26-2007 09:11 AM

ok an example:

put in the midlle of the screen
a clock...

alienDog 02-26-2007 09:55 AM

take a look at watch command (man watch)

matthewg42 02-26-2007 10:25 AM

Quote:

Originally Posted by Filipe
ok an example:

put in the midlle of the screen
a clock...

In what way is that like top? Do you mean that is used the [n]curses API?

Filipe 02-26-2007 10:26 AM

in the midlle of the screen a clock
when i type "S" displays seconds
when i type "s" hide seconds

:-)

alienDog 02-26-2007 10:32 AM

Quote:

Originally Posted by Filipe
in the midlle of the screen a clock
when i type "S" displays seconds
when i type "s" hide seconds

:-)

Hmm... this just started to look like homework to me... Study while-loop and read command of bash. That should get you started.

Filipe 02-26-2007 10:40 AM

YES !
curses API !
i think thats it...



ps: funny - the procinfo program that works like the same way top does donīt include curses...

matthewg42 02-26-2007 10:47 AM

There are curses bindings for several languages. Take your pick. C, Python, Perl, TCL, PHP... I'm sure there are more.

cfaj 02-27-2007 05:47 PM

Quote:

Originally Posted by Filipe
I would like to write a program to
display some variable info in shell
like "top" program refreshing automaticly

where can i view infos and simple examples
to achieve this ?

Thank you very much.

Do you mean like this:

Code:

SLEEPTIME=3
watch -n$SLEEPTIME "echo \$RANDOM"



All times are GMT -5. The time now is 09:36 AM.