08-18-2011
List of Running Jobs In Last 4 Hours
Hi Experts,
Please help me in this.
I am trying this code on AIX 5.3.
I need list of jobs that executed in last 4 hours.
I have a schedule on this script - cron executes it and sends mail to me for every 2 hours.
I have a Job time and have around 100 jobs those execute daily.
What all i need is when my cron executes below scripts it should capture list of jobs executed in last 4 hours.
Code:
Code :
#!/usr/bin/sh
#Scripted by Raju B on Aug062011#
#Datastge Jobs monitoring script
cd /QIS2FTP/scripts/Scripts
#Removing Last Run Jobstatus.txt file.
rm /QIS2FTP/scripts/Scripts/Jobstatus.txt
#Printing Output in Jobstatus.txt
Jobstatus=/QIS2FTP/scripts/Scripts/Jobstatus.txt
echo "JobName,StartDateTime,EndDateTime,Status " >>$Jobstatus
echo "------------------------------------------------------------" >>$Jobstatus
#set -x
# import my environment
. /QIS2FTP/dsclientprod/home/my.env
#Variables declaration
#List of all jobs in DS QIS2 Project
DSJoblist=`dssearch -ljobs -matches -sub -oc QIS2 * |cut -f2 -d'\'|awk '{print $1}'`
Project=QIS2
SysDate=`date +%Y%m%d`
for i in $DSJoblist
do
#DSJobStatus variable for collecting Job start and End time,Job duration and Job status
DSJobStatus=`dsjob -report $Project $i 2> /dev/null | grep "Job" | cut -f2 -d'='`
StartTime=`echo $DSJobStatus | cut -f1,2 -d' '`
EndTime=`echo $DSJobStatus | cut -f3,4 -d' '`
JobStat=`dsjob -report $Project $i | grep status | awk -F= ' { print $2; } ' | awk ' { print $1; } '`;
JobName=`dssearch -ljobs -matches -sub -oc QIS2 $i`
#Dateformat 20110805
JobRunDate=`echo $StartTime |awk '{print $1}'|sed 's/-//'|sed 's/-//'`
#Time in hours ex: 09
JobTimeH=`echo $StartTime |awk '{print $2}'|cut -f1 -d':'`
JobStTime=`echo "$JobTimeH"`
#Time in hours ex: 09
SystemHours=`date +%H`
if [ "$SystemHours" -eq "01" ]
then CurSysHrs=`echo "21"`
fi
if [ "$SystemHours" -eq "02" ]
then CurSysHrs=`echo "22"`
fi
if [ "$SystemHours" -eq "03" ]
then CurSysHrs=`echo "23"`
fi
if [ "$SystemHours" -eq "04" ]
then CurSysHrs=`echo "00"`
fi
if [ "$SystemHours" -ge "05" ]
then CurSysHrs=`echo "$SystemHours"+"-4" |bc`
fi
#Going back 4 hours for system time in a day
#Static="-4"
#Going 4 hour back from local time zone EST.
#CurSysHrs=`TZ=EDT-4:00 date '+%H%M'`
#echo "Print Current time before 4 hours $CurSysHrs"
if [ "$SysDate" == "$JobRunDate" ] && [ "$JobStTime" -ge "$CurSysHrs" ] && [ "$JobStTime" -le "$SystemHours" ]
then
if [ "x1" == "x${JobStat}" ] || [ "x0" < "x${JobStat}" ] || [ "x2" != "x${JobStat}" ]
then
echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus
fi
fi
done
#set +
---------- Post updated at 12:36 PM ---------- Previous update was at 12:35 PM ----------
Please validate this code :
Code:
Code :
#!/usr/bin/sh
#Scripted by Raju B on Aug062011#
#Datastge Jobs monitoring script
cd /QIS2FTP/scripts/Scripts
#Removing Last Run Jobstatus.txt file.
rm /QIS2FTP/scripts/Scripts/Jobstatus.txt
#Printing Output in Jobstatus.txt
Jobstatus=/QIS2FTP/scripts/Scripts/Jobstatus.txt
echo "JobName,StartDateTime,EndDateTime,Status " >>$Jobstatus
echo "------------------------------------------------------------" >>$Jobstatus
#set -x
# import my environment
. /QIS2FTP/dsclientprod/home/my.env
#Variables declaration
#List of all jobs in DS QIS2 Project
DSJoblist=`dssearch -ljobs -matches -sub -oc QIS2 * |cut -f2 -d'\'|awk '{print $1}'`
Project=QIS2
SysDate=`date +%Y%m%d`
for i in $DSJoblist
do
#DSJobStatus variable for collecting Job start and End time,Job duration and Job status
DSJobStatus=`dsjob -report $Project $i 2> /dev/null | grep "Job" | cut -f2 -d'='`
StartTime=`echo $DSJobStatus | cut -f1,2 -d' '`
EndTime=`echo $DSJobStatus | cut -f3,4 -d' '`
JobStat=`dsjob -report $Project $i | grep status | awk -F= ' { print $2; } ' | awk ' { print $1; } '`;
JobName=`dssearch -ljobs -matches -sub -oc QIS2 $i`
#Dateformat 20110805
JobRunDate=`echo $StartTime |awk '{print $1}'|sed 's/-//'|sed 's/-//'`
#Time in hours ex: 09
JobTimeH=`echo $StartTime |awk '{print $2}'|cut -f1 -d':'`
JobStTime=`echo "$JobTimeH"`
#Time in hours ex: 09
SystemHours=`date +%H`
if [ "$SystemHours" -ge "05" ]
then CurSysHrs=`echo "$SystemHours"+"-4" |bc`
fi
#Going back 4 hours for system time in a day
#Static="-4"
#Going 4 hour back from local time zone EST.
#CurSysHrs=`TZ=EDT-4:00 date '+%H%M'`
#echo "Print Current time before 4 hours $CurSysHrs"
#Jobs Running After 08 PM and Before12 AM
if [ "$SysDate" == "$JobRunDate" ] && [ "$SystemHours" -eq "0" ]
then
if [ "$JobStTime" -ge "20" ] || [ "$JobStTime" -le "0" ]
then
if [ "x1" == "x${JobStat}" ] || [ "x0" < "x${JobStat}" ] || [ "x2" != "x${JobStat}" ]
then
echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus
fi
fi
fi
#Jobs Running After 09 PM and Before 01 AM
if [ "$SysDate" == "$JobRunDate" ] && [ "$SystemHours" -eq "01" ]
then
if [ "$JobStTime" -ge "21" ] || [ "$JobStTime" -le "1" ]
then
if [ "x1" == "x${JobStat}" ] || [ "x0" < "x${JobStat}" ] || [ "x2" != "x${JobStat}" ]
then
echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus
fi
fi
fi
#Jobs Running After 10 PM an Before 02 AM
if [ "$SysDate" == "$JobRunDate" ] && [ "$SystemHours" -eq "02" ]
then
if [ "$JobStTime" -ge "22" ] || [ "$JobStTime" -le "2" ]
then
if [ "x1" == "x${JobStat}" ] || [ "x0" < "x${JobStat}" ] || [ "x2" != "x${JobStat}" ]
then
echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus
fi
fi
fi
#Jobs Running After 11 an Before 03 AM
if [ "$SysDate" == "$JobRunDate" ] && [ "$SystemHours" -eq "03" ]
then
if [ "$JobStTime" -ge "23" ] || [ "$JobStTime" -le "3" ]
then
if [ "x1" == "x${JobStat}" ] || [ "x0" < "x${JobStat}" ] || [ "x2" != "x${JobStat}" ]
then
echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus
fi
fi
fi
#Jobs Running After 12 AM and Before04 AM
if [ "$SysDate" == "$JobRunDate" ] && [ "$SystemHours" -eq "04" ]
then
if [ "$JobStTime" -ge "00" ] || [ "$JobStTime" -le "4" ]
then
if [ "x1" == "x${JobStat}" ] || [ "x0" < "x${JobStat}" ] || [ "x2" != "x${JobStat}" ]
then
echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus
fi
fi
fi
#Jobs Running atfter 05 AM
if [ "$SysDate" == "$JobRunDate" ] && [ "$SystemHours" -ge "05" ]
then
if [ "$JobStTime" -ge "$CurSysHrs" ] then
if [ "x1" == "x${JobStat}" ] || [ "x0" < "x${JobStat}" ] || [ "x2" != "x${JobStat}" ]
then
echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus
fi
fi
fi
done
#set +
Last edited by rajubollas; 08-18-2011 at 04:49 AM ..
Reason: Removed or condition
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi Frens,
I want to list some files from a directory, which contains "DONE" in their name, i am receiving files every minute. In this i want to list all the files which are newer than 6 hours but older than 3 hours, of current time
i dont want my list to contain the latest files which are ... (4 Replies)
Discussion started by: Prat007
4 Replies
2. UNIX for Dummies Questions & Answers
im doing at now <return>
touch ~/Desktop/file.txt
<ctrl d>
and file is never created though it says job 7 at Wed Mar 17 15:15:55 2010
why? (4 Replies)
Discussion started by: glev2005
4 Replies
3. UNIX for Dummies Questions & Answers
Hi,
Can any one help me on this.
How to capture the running process for two hours with an interval of 10 sec.
Thanks in andvance
Double post, continued here, thread closed (0 Replies)
Discussion started by: sarathkumar
0 Replies
4. Shell Programming and Scripting
Hi,
Can any one help me on this.
How to capture the running process for two hours with an interval of 10 sec.
Thanks in andvance (1 Reply)
Discussion started by: sarathkumar
1 Replies
5. Shell Programming and Scripting
Hi,
How can i capture the running process for 2 hours.
Thanks in advance.:b: (1 Reply)
Discussion started by: sarathkumar
1 Replies
6. Shell Programming and Scripting
How can I print ONLY processes running for more than 24 hours. Using ps command or any other method
I use this to get a whole list.
ps -eo pid,pcpu,pmem,user,args,etime,cmd --sort=start_time
We can also sort the outout of the above command to list processes older than 24 hours using... (9 Replies)
Discussion started by: anil510
9 Replies
7. UNIX for Dummies Questions & Answers
Hi All,
new to the forum and new to Unix but I have an issue which is annoying on a new level. I have included a short and full version for anyone needing more information.
Short Version
I am running a set of scripts that work and run fine. one of the scripts arranges the first... (4 Replies)
Discussion started by: Delboy4000
4 Replies
8. UNIX for Beginners Questions & Answers
Hi,
Is it possible to display processes which have been running for more than a 5hrs using a variation of the ps -ef command?
Regards,
Manny (5 Replies)
Discussion started by: mantas44
5 Replies
9. UNIX for Beginners Questions & Answers
HI
can someone help me to check the process running more than 2 hours.
I have the below command which shows the time and process id, however, I only need the processes running more than 2 hours. (8 Replies)
Discussion started by: Vinod
8 Replies