Find the answer to your Linux question:
Results 1 to 4 of 4

Thread: Execution Time

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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
    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).
    ps aux |grep $0|awk '{print $10}'

  3. #3
    Why grep for the script when you have the PID. Here's a test script.

    START_TIME="`ps -p $$ -o bsdtime=`"
    integer _ct=0
    while [ $_ct -lt 1000000 ]
    END_TIME="`ps -p $$ -o bsdtime=`"

  4. $spacer_open
  5. #4
    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