CurrentTime-4 hours


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CurrentTime-4 hours
# 1  
Old 08-11-2011
CurrentTime-4 hours

Hi,
Good Afternoon!
I am writing this script on "sh" and have Variables as below.
Code:
#Time in hours ex: 09
JobTime=`echo $StartTime |awk '{print $2}'|cut -f1 -d':'`
SystemHours=`date +%H`

How can go 4 hours back for each variable in a day?


Another Question?
Code:
JobStat=`dsjob -report $Project $i | grep status | awk -F= ' { print $2; } ' | awk ' { print $1; } '`;
if [ "$SysDate" == "$JobRunDate" ] && [ "$JobStTime" -ge "$CurSysHrs" ] && [ [ "x3" >= "x${JobStat}" ] || [ "x0" != "x${JobStat}" ] || [ "x2" != "x${JobStat}" ] ] 
then
{
echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus
}
fi

I tried this
Code:
[ [ "x3" >= "x${JobStat}" || "x0" != "x${JobStat}" || "x2" != "x${JobStat}" ] ] and [ [ "x3" -ge "x${JobStat}" || "x0" -ne "x${JobStat}" || "x2" -ne "x${JobStat}" ] ]

also
Please help me in if condition with "||" Statement.

Moderator's Comments:
Mod Comment Please use [CODE] tags when posting source listings

Last edited by rajubollas; 08-11-2011 at 06:36 PM.. Reason: Tags
# 2  
Old 08-11-2011
Don't know which flavor of unix OS you are on, but if you have gnu date (which linux has by default) , you can use:

Code:
date -d "4 hours ago"

# 3  
Old 08-12-2011
This option i tried but no luck

I am Using AIX 5.3
# 4  
Old 08-12-2011
Why not just set TZ to 4 hours before your current timezone:

eg (for New Delhi):

Code:
$ date
Fri Aug 12 10:27:01 IST 2011
 
$ TZ=GTM-1:30 date
Fri Aug 12 06:27:12 GTM 2011

This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 08-12-2011
Unfortunately I don't have access to AIX. Does the below work on AIX? see if it works, if so we may be in luck. Normally this prints UNIX epoch time. If we get that from date +%s, we can play around with that.

Code:
date +%s or date '+%s', try both

---------- Post updated at 12:58 AM ---------- Previous update was at 12:57 AM ----------

Quote:
Originally Posted by Chubler_XL
Why not just set TZ to 4 hours before your current timezone:

eg (for New Delhi):

Code:
$ date
Fri Aug 12 10:27:01 GMT 2011

$ TZ=GTM-1:30 date
Fri Aug 12 06:27:12 GTM 2011

I like that, very clever and easy, nice !
This User Gave Thanks to dude2cool For This Post:
# 6  
Old 08-14-2011
Thanks for the Help,
Still i am looking for IF then Else part.

Code:
JobStat=`dsjob -report $Project $i | grep status | awk -F= ' { print $2; } ' | awk ' { print $1; } '`;
if [ "$SysDate" == "$JobRunDate" ] && [ "$JobStTime" -ge "$CurSysHrs" ] && [ [ "x3" >= "x${JobStat}" ] || [ "x0" != "x${JobStat}" ] || [ "x2" != "x${JobStat}" ] ] 
then
{
echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus
}
fi

---------- Post updated at 10:19 AM ---------- Previous update was at 08:55 AM ----------

Thanks for the response.
But here i have to compare output numbers coming from two different time variables.
My question is i have to go 4 hours back from current time all the time in day(24hrs) and trying to capture the result list of jobs those executed in last four hours.

Pleae see entire 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':'`
JobTimeM=`echo $StartTime |awk '{print $2}'|cut -f2 -d':'`
JobStTime=`echo "$JobTimeH$JobTimeM"`
#Going 4 hour back from local time zone EST.
CurSysHrs=`TZ=GTM+1:00 date '+%H%M'`
#echo "Print Current time before 4 hours $CurSysHrs"
if [ "$SysDate" == "$JobRunDate" ] && [ "$CurSysHrs" -ge "$JobStTime" ]
then
if [ "x1" == "x${JobStat}" ]
then
echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus
fi
fi
# if [ "$SysDate" == "$JobRunDate" ] && [ "$CurSysHrs" -ge "$JobStTime" ]
# then if [ "x0" != "x${JobStat}" ]
# then 
# echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus
# 
# fi 
# fi
# if [ "$SysDate" == "$JobRunDate" ] && [ "$CurSysHrs" -ge "$JobStTime" ]
# then if [ "x2" != "x${JobStat}" ]
# then 
# echo "$JobName,$StartTime,$EndTime,$JobStat" >>$Jobstatus 
# fi 
# fi
done
#set +


Last edited by zxmaus; 08-14-2011 at 01:55 AM.. Reason: PSIC_FACT_CLAIM changed * for all jobs
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get the no of hours between days

Hi, i have a date 1- 2013101511 date2 -2013101812 need toget the no of hours between them,can any one tellme the logic. (6 Replies)
Discussion started by: sandeep karna
6 Replies

2. Shell Programming and Scripting

Need help looking for missing hours.

I have a file that should cover a days worth of stats, at the beginning of each 15 minute report I have a unique header that looks like the below example. The "0000" and "0015" will change in the header line to show which 15 Minute interval the report is covering and of course from day to day the... (7 Replies)
Discussion started by: fsanchez
7 Replies

3. Shell Programming and Scripting

Exit script after exactly 3 hours

Need to run a script for exactly 3 hours. It will have while loop which is to keep running until its 3 hours since the script's invocation time and then exit the script. Script could be invoked at any time. May have to change the number of hours later as per need. Are there any existing... (5 Replies)
Discussion started by: Prev
5 Replies

4. Shell Programming and Scripting

ps -ef |grep 24 hours

I need to grep PIDs older than 24 hours (1 day) or more. ps -ef |grep ??? Please advise. (10 Replies)
Discussion started by: Daniel Gate
10 Replies

5. AIX

cron off by 5 hours

stupid question im sure, but its frustrating My cron jobs are off by 5 hours. My system time is right but all of my cron jobs are running approximately 5 hours late. Any idea why? (4 Replies)
Discussion started by: mshilling
4 Replies

6. What is on Your Mind?

How Many hours on Computer?

How many hours you spend on Computer in a day??? (10 Replies)
Discussion started by: malcomex999
10 Replies

7. Shell Programming and Scripting

how to list files between last 6 hours to 3 hours

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

8. SCO

System restarting itself every after 20-24 hours

HI We have Compaq ML350 G2 server with UNIX SCO 5.0.5 OS , can anyone help us to get rid about the system restarting problem by itself every after2-24 hours with following error " MEMORY CORE DUMP " . Waiting for your ASAP help. Thank You . (4 Replies)
Discussion started by: munirh
4 Replies

9. Post Here to Contact Site Administrators and Moderators

Have we just had a rollback of a few hours?

Have we just had a rollback of a few hours? (1 Reply)
Discussion started by: porter
1 Replies
Login or Register to Ask a Question