Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Utility for getting date of scritpt execution

  1. #1
    Join Date
    Nov 2015
    Beans
    15

    Utility for getting date of scritpt execution

    Hello all!

    I want to create some utility which will allow to get date of start execution and date of finishing some arbitrary script which filename was passed for this utility like a input param[It's assumed that scritp was started week ago and completed execution 1-2 days ago ]. I guess tha't bash is more preferable, But there is some problem , I think that parsing of Ubuntu logs is not simple tasks.
    May be there is another way? My be somebody did such thing?
    Thanks

  2. #2
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Utility for getting date of scritpt execution

    If you're looking for the duration of the script, you can launch it with "time"

    Code:
    time /path/to/some/script

  3. #3
    Join Date
    Nov 2015
    Beans
    15

    Re: Utility for getting date of scritpt execution

    thnx, for reply.
    But, No, I do not want get duration.
    I need date of script successful finishing( I assume that it works without some interruption[cron etc])

  4. #4
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Utility for getting date of scritpt execution

    Ok. Then you can either append date to the script itself or to the line when the script is called.

    Code:
    /path/to/some/script ; /bin/date +"Script done %F %T" > /var/log/script.log
    If you want the end time only if the script was successful, use &&

    Code:
    /path/to/some/script && /bin/date +"Script done %F %T" > /var/log/script.log

  5. #5
    Join Date
    Nov 2015
    Beans
    15

    Re: Utility for getting date of scritpt execution

    Hm...all my attempts failed - "script: command not found"
    Path is correct.

  6. #6
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Utility for getting date of scritpt execution

    Can you show how you are calling the script?

  7. #7
    Join Date
    Nov 2015
    Beans
    15

    Re: Utility for getting date of scritpt execution

    Code:
    user01@amrtkt: sudo /home/user01/scripts/t123.py ; /bin/date +"Script done %F %T" > ~/script.log
    t123.py
    contains just
    Code:
    print "123"
    Result is "t123.py: command not found", Did I miss something?

  8. #8
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Utility for getting date of scritpt execution

    Quote Originally Posted by udragu View Post
    Result is "t123.py: command not found", Did I miss something?

    Yes. The first line of the script needs to tell which interpreter to use. So t123.py should contain the following at the minimum.

    Code:
    #!/usr/bin/python
    
    print "123"

  9. #9
    Join Date
    Nov 2015
    Beans
    15

    Re: Utility for getting date of scritpt execution

    First
    t123.py: command not found - nothing changes
    t123.py works successful
    Second:
    I think you do not understand me.
    Of course, there is a way to add some code into script which will save date and the end of it's execution, but the main Idea is to get date postfactum. For example, some script was started.Duration two weeks, just for fun). Execution of it was completed or interrupted(may be power outage was happened). And I need to know was result successful or not. I need something like windows event log but for scripts.

  10. #10
    Join Date
    Nov 2015
    Beans
    15

    Re: Utility for getting date of scritpt execution

    I understand that there is no method if script doesn't logs anything
    If somebody intersted in such cases only auditit could be very useful

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •