Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   log timestamp a script is used (http://www.velocityreviews.com/forums/t911227-log-timestamp-a-script-is-used.html)

GU 08-17-2009 12:02 PM

log timestamp a script is used
 
Hi,

currently we've a lot of scripts, but don't know how often each one is
used.

To clean up those jumble of scripts i wanna log the timestamp a script
is used.

For that i like to do something like this:
system "echo $0 `date` >> /tmp/script_used.log";
but WITHOUT modifing each skript itself.

i would imagine two ways:
1) set of environment to tell perl to do something like that (but
which setting would do that?, alias would not work --> different users
- different shells)
2) recompilation of perl (but i havn't compiled perl jet and don't
know how to do that)

Is there a way to do this?


thx
Gerhard

C.DeRykus 08-18-2009 12:43 AM

Re: log timestamp a script is used
 
On Aug 17, 5:02*am, GU <gerhard_ulr...@yahoo.de> wrote:
> Hi,
>
> currently we've a lot of scripts, but don't know how often each one is
> used.
>
> To clean up those jumble of scripts i wanna log the timestamp a script
> is used.
>
> For that i like to do something like this:
> system "echo $0 `date` >> /tmp/script_used.log";
> but WITHOUT modifing each skript itself.
>
> i would imagine two ways:
> 1) set of environment to tell perl to do something like that (but
> which setting would do that?, alias would not work --> different users
> - different shells)
> 2) recompilation of perl (but i havn't compiled perl jet and don't
> know how to do that)
>
> Is there a way to do this?
>


One possibility: save the actual perl executable off somewhere
and substitute a short C program that'd do the logging and then
just exec the saved perl.

(This should be fairly easy on Unix but may need some more tweaks
if other O/S's are in the fray).

--
Charles DeRykus



Gerhard 08-24-2009 12:56 PM

Re: log timestamp a script is used
 
Thanks,

your first solution is very easy to use and does what i want it to
do.
I've wrote a simple Package:
"
system "echo $0 `date` >>/tmp/Scripts_used.lst";
1;
"
set the environment and have restartet my job-scheduler (to have the
correct
environment).

That's all and it works fine. I'll get my logs and can count the
numbers each
script is used.

THX
Gerhard

Jürgen Exner 08-24-2009 01:14 PM

Re: log timestamp a script is used
 
Gerhard <gerhard_ulrike@yahoo.de> wrote:
>I've wrote a simple Package:
>"
>system "echo $0 `date` >>/tmp/Scripts_used.lst";
>1;
>"


To avoid the overhead of forking of a new process just to get the date
you could have used localtime():

system ("echo $0 ". localtime) >>/tmp/Scripts_used.lst";

>That's all and it works fine.


But if it works fine then that's all that matters.

jue

Tim McDaniel 08-24-2009 03:36 PM

Re: log timestamp a script is used
 
In article <v94595pjt7anitu990qekgfmiig6jia1sv@4ax.com>,
Jürgen Exner <jurgenex@hotmail.com> wrote:
>Gerhard <gerhard_ulrike@yahoo.de> wrote:
>>I've wrote a simple Package:
>>"
>>system "echo $0 `date` >>/tmp/Scripts_used.lst";
>>1;
>>"

>
>To avoid the overhead of forking of a new process just to get the
>date you could have used localtime():
>
> system ("echo $0 ". localtime) >>/tmp/Scripts_used.lst";


Well, you can avoid processes entirely by opening
/tmp/Scripts_used.lst in Perl with '>>' mode, and printing $0 and
localtime to it.

>But if it works fine then that's all that matters.


Yeah. And if this is, for example, running only several times a day,
the overhead is negligable. All too often, micro-optimization
takes macro-effort to produce micro-results.

--
Tim McDaniel, tmcd@panix.com

Gerhard 09-02-2009 10:26 AM

Re: log timestamp a script is used
 
On 24 Aug., 17:36, t...@panix.com (Tim McDaniel) wrote:
>
> Yeah. *And if this is, for example, running only several times a day,
> the overhead is negligable. *All too often, micro-optimization
> takes macro-effort to produce micro-results.
>


i see you and me we know of the german saying "wer misst misst
mist" ....


thanks for the hint, i've thougt about that and appreciated to be
about one thousand calls a day. (the counter exhibits that there are
"only" 700 a day)

That seems to be a lot, but the scripts i'd taken over look alike
scripts from a shell2perl converter. Within that scripts there is a
plenty of commands like this ones:
$first=`cd $workingdir; ls SA*.txt|sort|head -1`
$last ='cd $workingdir; ls SA*.txt|sort|tail -1`
etc.

I've counted 42 backticks and system-calls in only one script ....
therefore i had no scruple to do it in the same way.

Gerhard


All times are GMT. The time now is 09:07 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.