Find the answer to your Linux question:
Results 1 to 4 of 4
I am writting a script in the ksh shell and am trying to find a way to report the total execution time of the script without requiring the user to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2008
    Posts
    3

    Execution Time


    I am writting a script in the ksh shell and am trying to find a way to report the total execution time of the script without requiring the user to specify the time function when executing the script.
    Does anyone have any examples they have used. I have been setting up two date variables (one at the beginning $START_TIME and one at the end $END_TIME) and then do some calulation of the difference and display is to the user in minutes. No matter what I do it keeps giving me syntax errors.
    any help

  2. #2
    Linux Guru bigtomrodney's Avatar
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    6,133
    You could get that from the ps command. the execution time is column 10, $0 is the variable that holds the script name (at least in bash, I don't use ksh myself).
    Code:
    ps aux |grep $0|awk '{print $10}'

  3. #3
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Why grep for the script when you have the PID. Here's a test script.

    Code:
    #!/bin/ksh
    
    START_TIME="`ps -p $$ -o bsdtime=`"
    integer _ct=0
    while [ $_ct -lt 1000000 ]
        do
             _ct=_ct+1
        done
    END_TIME="`ps -p $$ -o bsdtime=`"
    
    echo $START_TIME $END_TIME

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Jul 2008
    Posts
    3
    that worked GREAT! Thanks.

Posting Permissions

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