LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-26-2007, 07:57 AM   #1
Filipe
LQ Newbie
 
Registered: Dec 2005
Posts: 23

Rep: Reputation: 15
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.
 
Old 02-26-2007, 08:04 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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
 
Old 02-26-2007, 08:09 AM   #3
Filipe
LQ Newbie
 
Registered: Dec 2005
Posts: 23

Original Poster
Rep: Reputation: 15
like "top" program...
 
Old 02-26-2007, 08:42 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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.
 
Old 02-26-2007, 09:11 AM   #5
Filipe
LQ Newbie
 
Registered: Dec 2005
Posts: 23

Original Poster
Rep: Reputation: 15
ok an example:

put in the midlle of the screen
a clock...
 
Old 02-26-2007, 09:55 AM   #6
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
take a look at watch command (man watch)
 
Old 02-26-2007, 10:25 AM   #7
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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?
 
Old 02-26-2007, 10:26 AM   #8
Filipe
LQ Newbie
 
Registered: Dec 2005
Posts: 23

Original Poster
Rep: Reputation: 15
in the midlle of the screen a clock
when i type "S" displays seconds
when i type "s" hide seconds

:-)
 
Old 02-26-2007, 10:32 AM   #9
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
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.
 
Old 02-26-2007, 10:40 AM   #10
Filipe
LQ Newbie
 
Registered: Dec 2005
Posts: 23

Original Poster
Rep: Reputation: 15
YES !
curses API !
i think thats it...



ps: funny - the procinfo program that works like the same way top does donīt include curses...
 
Old 02-26-2007, 10:47 AM   #11
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
There are curses bindings for several languages. Take your pick. C, Python, Perl, TCL, PHP... I'm sure there are more.
 
Old 02-27-2007, 05:47 PM   #12
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
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"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SHell program in c SatYr_84 Linux - Software 1 10-03-2005 05:49 PM
TOP, showing a program i don't believe i started JerryMcFarts Linux - Security 4 04-20-2005 01:37 AM
HELP!! I need to program a shell pleowulf Programming 2 02-11-2005 01:12 PM
system("top") in a C program giving problems when the C prg is run by cron rags2k Programming 1 09-02-2004 03:25 PM
Shell Program Veteq Programming 12 08-18-2004 07:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration