Hi ,
I need to find runtime of jobs.
I have written below script to get start and end times for a list of jobs.
#!/bin/bash
InputFile_Name=/var/tmp/cgk/pre2_oper_status_7amcheck_jobs
if [ ! -f $InputFile_Name ]
then
echo "File: $InputFile_Name doesn't exist , Pls check & run again"
echo "Exiting the script"
exit 1;
fi
while read Job_Name
do
if [ ! -z $Job_Name ]
then
len=`echo $Job_Name | awk '{print length }'`
if [ $len -ge 24 ]
then
autorep -j $Job_Name -w | grep -i $Job_Name | awk '{ print $1 "\t\t\t\t " $2 " " $3 " " $4 " " $5 " " $6 }'
else
autorep -j $Job_Name -w | grep -i $Job_Name | awk '{ print $1 "\t\t\t\t\t\t " $2 " " $3 " " $4 " " $5 " " $6 }'
fi
else
echo ""
fi
done < $InputFile_Name
echo ""
exit 0
Output :--
jobname1 04/06/2011 09:33:37 04/06/2011 09:34:04 SU
jobname2 04/06/2011 09:51:33 04/06/2011 10:02:28 SU
jobname3 04/06/2011 09:51:37 04/06/2011 10:08:56 SU
I am trying to use script in below link
But i am not able to get the run times of each job in HH:MIN:SEC
Can some one assist on this to get run times of each job.
The awk you have referred uses different format, try this one,
user@tioman> (/home/user) $ cat time.awk
{
split($2,sdate,"/")
split($3,stime,":")
split($4,edate,"/")
split($5,etime,":")
s_secs=mktime(sdate[3]" "sdate[2]" "sdate[1]" "stime[1]" "stime[2]" "stime[3])
e_secs=mktime(edate[3]" "edate[2]" "edate[1]" "etime[1]" "etime[2]" "etime[3])
print $1,strftime("%T",e_secs-s_secs)
}
You have new mail in /var/spool/mail/user
user@tioman> (/home/user) $ awk -f time.awk test.txt
bname1 07:30:27
jobname2 07:40:55
jobname3 07:47:19
user@tioman> (/home/user) $
I have a different time zone set here, so my output has 7 hrs 30 mins plus in each one.
please post your output as well.
Hi Kumaran,
Instead of writing awk script is there any way we can do on the command line like i am able to print other columns. ??
awk '{ print $1 "\t\t\t\t " $2 " " $3 " " $4 " " $5 " " $6 }'
Taking time difference isn't easy job atleast in unix prompt, so you need few lines of code to do these, awk script isn't big thing and still you can keep it and change the below line
autorep -j $Job_Name -w | grep -i $Job_Name | awk '{ print $1 "\t\t\t\t " $2 " " $3 " " $4 " " $5 " " $6 }'
to
autorep -j $Job_Name -w | grep -i $Job_Name | awk '{ print $1 "\t\t\t\t " $2 " " $3 " " $4 " " $5 " " $6 }'|awk -f time.awk
This should work out for you
Do you want the time elapsed between start and end time of each job??
regards,
Ahamed
did you try using time command, I'm not sure though what you mean by job here .
Hi Kumaran,
Looks like there is some problem with strftime
vi time.awk
"time.awk" 15 lines, 449 characters
{
split($2,sdate,"/")
split($3,stime,":")
split($4,edate,"/")
split($5,etime,":")
s_secs=mktime(sdate[3]" "sdate[2]" "sdate[1]" "stime[1]" "stime[2]" "stime[3])
e_secs=mktime(edate[3]" "edate[2]" "edate[1]" "etime[1]" "etime[2]" "etime[3])
#print $0
#printf ("%s", strftime("%H:%M:%S", e_secs - s_secs, 1))
print e_secs
print s_secs
print e_secs-s_secs
#printf "%s\n", strftime("%H:%M:%S", e_secs - s_secs, 1)
print $1,strftime("%T",e_secs-s_secs)
}
awk: syntax error near line 14
awk: illegal statement near line 14
:/var/tmp/gautam]$ uname
SunOS
If i remove the line containing strftime it works fine
:/var/tmp/gautam]$ autorep -j jobname -w |grep jobname |awk '{ print $1 "\t\t\t\t\t\t " $2 " " $3 " " $4 " " $5 " " $6 }'|awk -f time.awk
2011 06 06 10 30 26
2011 06 06 10 30 25
0
:/var/tmp/gautam]$
---------- Post updated at 03:37 AM ---------- Previous update was at 03:27 AM ----------
Hi Kumaran,
Looks like there is some problem with strftime
vi time.awk
"time.awk" 15 lines, 449 characters
{
split($2,sdate,"/")
split($3,stime,":")
split($4,edate,"/")
split($5,etime,":")
s_secs=mktime(sdate[3]" "sdate[2]" "sdate[1]" "stime[1]" "stime[2]" "stime[3])
e_secs=mktime(edate[3]" "edate[2]" "edate[1]" "etime[1]" "etime[2]" "etime[3])
#print $0
#printf ("%s", strftime("%H:%M:%S", e_secs - s_secs, 1))
print e_secs
print s_secs
print e_secs-s_secs
#printf "%s\n", strftime("%H:%M:%S", e_secs - s_secs, 1)
print $1,strftime("%T",e_secs-s_secs)
}
awk: syntax error near line 14
awk: illegal statement near line 14
:/var/tmp/gautam]$ uname
SunOS
If i remove the line containing strftime it works fine
:/var/tmp/gautam]$ autorep -j jobname -w |grep jobname |awk '{ print $1 "\t\t\t\t\t\t " $2 " " $3 " " $4 " " $5 " " $6 }'|awk -f time.awk
2011 06 06 10 30 26
2011 06 06 10 30 25
0
:/var/tmp/gautam]$
Try to use gawk or nawk if you are using solaris.