LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Monitoring scripts (https://www.linuxquestions.org/questions/linux-newbie-8/monitoring-scripts-4175427652/)

neoanomally 09-17-2012 10:48 AM

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

tronayne 09-17-2012 11:58 AM

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.

neoanomally 09-17-2012 12:30 PM

Quote:

Originally Posted by tronayne (Post 4782449)
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

unSpawn 09-17-2012 01:49 PM

Quote:

Originally Posted by neoanomally (Post 4782471)
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.

tronayne 09-17-2012 03:18 PM

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


Habitual 09-17-2012 05:31 PM

I've used "who loves you" for a couple of years now.

unSpawn 09-17-2012 06:23 PM

Quote:

Originally Posted by tronayne (Post 4782611)
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!


All times are GMT -5. The time now is 03:02 PM.