log timestamp a script is used

G

GU

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

C.DeRykus

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

Gerhard

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

Jürgen Exner

Gerhard said:
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
 
T

Tim McDaniel

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

Gerhard

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top