LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
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,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
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: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
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 Addict
 
Registered: Jan 2011
Posts: 8,353
Blog Entries: 11

Rep: Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327Reputation: 2327
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,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
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


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
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


All times are GMT -5. The time now is 06:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration