How to find the time taken for a script to run?

I have just written a Csh script and i want to find out how long does the script take to complete executing. Is there any codes which i can put into my script to capture its run time ?

check time command.ksh provide builtin variable SECONDS.not sure about csh.

you can capture begin time and end time. and then calculate execution time =)

I tried. See below. Both output of start and end time is identical. The runtime for the script actually lasted for few mins and not negligible! Pls help .Thanks

set time_start = `date '+%T%t%d_%h_06'`
set time_end = `date '+%T%t%d_%h_06'`

echo "$time_start"

BODY OF SCRIPT

echo "$time_end"

you mast set time_end after ending of script body.
for example

#!/bin/sh
time_start=`date '+%T%t%d_%h_06'`
echo "$time_start"

script body

time_end=`date '+%T%t%d_%h_06'`
echo "$time_end"

Oh i got it! Thanks.. but is there any code which i can use to find the difference between the 2 time ?

time_start=`date +%s`

script body

time_end=`date +%s`
time_exec=`expr $(( $time_end - $time_start ))`

echo "Execution time is $time_exec seconds"

1 Like

time scriptname.csh

Why do i receive the below info once i "time" this script ? How can i disable the time?

LOT_SUFFIX N30565PBS2P2
NFILES_ftped /export/home/tae/scripts/NFILES
PASS tae2eng
PNP_partno 57P9415
USER tae
ans y
argv ()
carry_on 1
cwd /export/home/tae/scripts/NFILES
date_launch 19-Sep-06
home /export/home/tae
lotid N30565PB
lotid1 D7N30565PB
nfile_selected n060914a_57P9415_0829GGQAMK_taaja160.asc
nfiles_dir /export/home/tae/scripts/test_nfiles
path (/bin /usr/bin /usr/ucb /etc .)
product odyssey35
reports_dir /export/home/tae/scripts/test_summary
script_home /export/home/tae/scripts
shell /bin/csh
status 0
suffix S2P2
term vt100
testerid taaja160
time_start 09:40:13
user tae

Wow this works great. Is there a way to get mili seconds too?