log timestamp a script is used

Discussion in 'Perl Misc' started by GU, Aug 17, 2009.

  1. GU

    GU Guest

    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
    GU, Aug 17, 2009
    #1
    1. Advertising

  2. GU

    C.DeRykus Guest

    On Aug 17, 5:02 am, GU <> 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
    C.DeRykus, Aug 18, 2009
    #2
    1. Advertising

  3. GU

    Gerhard Guest

    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
    Gerhard, Aug 24, 2009
    #3
  4. Gerhard <> 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
    Jürgen Exner, Aug 24, 2009
    #4
  5. GU

    Tim McDaniel Guest

    In article <>,
    Jürgen Exner <> wrote:
    >Gerhard <> 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,
    Tim McDaniel, Aug 24, 2009
    #5
  6. GU

    Gerhard Guest

    On 24 Aug., 17:36, (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
    Gerhard, Sep 2, 2009
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henrik_the_boss
    Replies:
    0
    Views:
    2,647
    Henrik_the_boss
    Nov 5, 2003
  2. Amratash
    Replies:
    0
    Views:
    519
    Amratash
    Apr 13, 2004
  3. =?Utf-8?B?VG9tIFdpbmdlcnQ=?=

    My.Log.Writeexception not writing to Application Event Log.

    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=, Jan 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,371
    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=
    Jan 20, 2006
  4. unomystEz
    Replies:
    0
    Views:
    548
    unomystEz
    Nov 19, 2006
  5. vj
    Replies:
    0
    Views:
    678
Loading...

Share This Page