LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-17-2012, 10:48 AM   #1
neoanomally
LQ Newbie
 
Registered: Nov 2010
Posts: 13

Rep: Reputation: 0
Monitoring scripts


Are there any built in commands that allow me to monitor when how often a script runs? I have an application and when that application is accessed there is a script that runs. We were looking to monitor how often it runs and how much %CPU and %MEM the script was taking up on average.

Thanks
 
Old 09-17-2012, 11:58 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
There aren't really any built-ins for doing what you're asking; however, it's quite simple to append information to a log file, say insert this in your progam
Code:
who am i >> /var/log/script.log
and you'll know who and when.

How much memory and CPU it takes, well, I dunno. You can look at sysstat, mpstat, sar, ps and maybe top (piped through grep and appended to a log file.

Hope this helps some.
 
Old 09-17-2012, 12:30 PM   #3
neoanomally
LQ Newbie
 
Registered: Nov 2010
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by tronayne View Post
There aren't really any built-ins for doing what you're asking; however, it's quite simple to append information to a log file, say insert this in your progam
Code:
who am i >> /var/log/script.log
and you'll know who and when.

How much memory and CPU it takes, well, I dunno. You can look at sysstat, mpstat, sar, ps and maybe top (piped through grep and appended to a log file.

Hope this helps some.
Thanks a lot, that definitely gives me some ideas.... So if I wanted to put both of those commands it would looks something like:

who am i | top | grep [program_name] >> /var/log/script.log?

EDIT: Never Mind; I figured it out. Thanks again!!

who am i; top | grep [program_name] >> /var/log/script.log

Last edited by neoanomally; 09-17-2012 at 12:36 PM. Reason: Solved it
 
Old 09-17-2012, 01:49 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by neoanomally View Post
EDIT: Never Mind; I figured it out. Thanks again!!

who am i; top | grep [program_name] >> /var/log/script.log
Sorry but that doesn't make sense. 'whoami' and 'who' are valid standard commands but 'am' and 'i' are not: he just gave you an example how to redirect stdout to a file.


Quote:
Originally Posted by neoanomally
I have an application and when that application is accessed there is a script that runs.
There's a lot of variables here like:
- What is the application? Just tell us the name OK?
- How or when is the application run? On local user login, command line, via CGI, cron job, when the Three Horsemen of the Apocalypse enter the bar, etc, etc?
- Does the script run a for a very short period of time?
- Does it run independent of the application or does the application run it?
- Who does the script run as?
- Does it access different resources during its run?
- Can you modify the script?
...and all of these matter.

The more we know about the application and its relation to the script the easier it will be to come up with a way less kludgy solution.
 
Old 09-17-2012, 03:18 PM   #5
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Uh, not to be contrary, but
Code:
fubar-trona-/home/trona: who am i
trona    pts/0        2012-09-17 16:15 (:0.0)
and
Code:
man who
...
If  FILE is not specified, use /var/run/utmp.  /var/log/wtmp as FILE is common.  If
ARG1 ARG2 given, -m presumed: `am i' or `mom likes' are usual.
...
 
1 members found this post helpful.
Old 09-17-2012, 05:31 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I've used "who loves you" for a couple of years now.
 
Old 09-17-2012, 06:23 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by tronayne View Post
Code:
If  FILE is not specified, use /var/run/utmp.  /var/log/wtmp as FILE is common.  If
ARG1 ARG2 given, -m presumed: `am i' or `mom likes' are usual.
Didn't know nor read that, thanks!
 
  


Reply



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
Error in shell scripts of monitoring node down events jayakumar01 Linux - Server 2 01-22-2012 01:55 AM
scripts......for monitoring... abhijeetdutta Linux - Software 4 10-02-2009 11:45 AM
network monitoring:unable to launch nagios network monitoring system oladapo1980 Linux - Newbie 0 07-21-2009 01:45 PM
Monitoring free memory with enterprise monitoring application Steelb Linux - Enterprise 2 02-13-2008 10:10 AM
VPN: Debian Scripts -> Mandriva 2006 Scripts Undefined Mandriva 0 11-30-2005 12:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:18 AM.

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