checking time stamp


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers checking time stamp
# 1  
Old 08-22-2007
Question checking time stamp

Hi,
I am having a script in which I am again calling a script, but before calling that script I need to perform a time check (say 1 - 2 am i.e. I would be able to call that script if time is between 1:00 am and 2:00 am) but this time stamp needs to be configurable.
can anybody suggest me how I can achive this..


Thanks in advance
Manvar
# 2  
Old 08-22-2007
MySQL

Quote:
Originally Posted by Manvar Khan
Hi,
I am having a script in which I am again calling a script, but before calling that script I need to perform a time check (say 1 - 2 am i.e. I would be able to call that script if time is between 1:00 am and 2:00 am) but this time stamp needs to be configurable.
can anybody suggest me how I can achive this..


Thanks in advance
Manvar

You can do something like this--

#!/bin/ksh
echo "To run a script in between a given time"
str1=`date | cut -d" " -f4`
str2=`echo $str1 | cut -d":" -f1`
if [[ $str2 -eq 13 ]] or if [[ $(date +%h) -eq 13 ]]
then
ksh test2
else
echo "Wrong"
fi


Thanks
Namish

Last edited by namishtiwari; 08-22-2007 at 05:19 AM..
# 3  
Old 08-22-2007
Without so many 'cut's
Code:
#! /bin/ksh

if [[ $(date +%H) -eq 01 ]] ; then
  echo "Judgement day has arrived"   # run the script
else
  echo "Judgement day has not arrived"
fi

# 4  
Old 08-22-2007
thanks Namish for your reply,
but this is not the solution I want, as per your solution

if [[ $str2 -eq 13 ]]

now in future if I want to change 13 to 15 then I have make changes in the code.
and I dont want to cahnge in the code.
I want my script capable of taking this time from some where outside this script.
I hope you got my problem.

Regards
Manvar
# 5  
Old 08-22-2007
Code:
#! /bin/ksh
#
#

case $# in
    2) start=$1; end=$2 ;;
    *) echo "Need a start and end time"; exit 1;;
esac

now=$(date +%H)
if [[ $now -ge $start && $now -lt $end ]] ;
then
    echo "Judgement Day has arrived."
else
    echo "Judgement Dat yet to arrive."
fi;

# 6  
Old 08-22-2007
thanks vino,
I am sorry I forgot to tell that we cannot use command line aurguments here (It is the requirement).

Regards
Manvar
# 7  
Old 08-22-2007
MySQL

Manvar,
You can read the time like this

echo "Enter the start time stamp"
read stime

echo "Enter the end time"
read etime

and do your manipulations on these variables itself.
is that going to help you.

Thanks
Namish
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Difference between time stamp

Hi All i have a file data like below format A, B 2016-04-14 16:30:00,2016-04-14 16:31:17 2016-04-14 16:40:00,2016-04-14 16:41:10 2016-04-14 16:50:00,2016-04-14 16:50:41 2016-04-14 17:00:00,2016-04-14 17:00:35 2016-04-14 17:10:00,2016-04-14 17:11:48 2016-04-14 17:20:00,2016-04-14 17:20:37 i... (2 Replies)
Discussion started by: Tarak_nath
2 Replies

2. Shell Programming and Scripting

Logs between two time stamp

I am creating log monitoring script and stuck up to get the logs between two time stamp. can you please help me to create the script to get the logs between two time stamp, for example, I need the complete logs between # Time: 150328 1:30:10 and # Time: 150328 19:10:57 OS : Cent OS 6.x... (8 Replies)
Discussion started by: zenkarthi
8 Replies

3. Shell Programming and Scripting

Time stamp Difference

I have a log file which wrote time stamp like this 2013-02-11 00:46:40.389037 2013-02-12 11:46:40.197045 can any one help me to get the time stamp difference of these two line in seconds. (4 Replies)
Discussion started by: netdbaind
4 Replies

4. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

5. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

6. Shell Programming and Scripting

regarding time stamp

hi everyone i am facing a strange problem here suppose content of my file is a=1,2,3 b=2,3,4 c=4,5,6 time= now the problem is i want to add value in front of time variable and the value should be i format only "HHMMSS" so it should be like this a=1,2,3 b=2,3,4 c=4,5,6... (3 Replies)
Discussion started by: aishsimplesweet
3 Replies

7. UNIX for Dummies Questions & Answers

How to get the next time stamp in perl?

Hi, I have to find the next time stamp in perl. Here is the code. @time = loaltime(time); print "\n Present time: $time:$time:$time \n"; For example if the time is: "12:55:02" after some process the time becomes 1:00:00. How do i check when it becomes 00:00 i.e from "12:55:02... (0 Replies)
Discussion started by: vanitham
0 Replies

8. Shell Programming and Scripting

greping with time stamp

Hi all, I want to grep a file name with time stamp as 30 minutes how can i??. Ex I will getting outputs in a file every minutes I want to grep it by a time intervals of 30 and show it . Any help will be great ! Thanks, Arun. (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

9. UNIX for Dummies Questions & Answers

capturing the time stamp

Hi All, I am working on a korn shell script. i have a file such as: DS.PETSCO.20060601203514.20060531.ctl_20060717124431 i have 2 problems here. 1) i have to capture the time stamp from the above file i.e this number 20060717124431. format of time stamp is YYYYMMDDHHMMSS. can... (4 Replies)
Discussion started by: pavan_test
4 Replies

10. Shell Programming and Scripting

Date Time Stamp

I'm trying to write a script that checks the DTS of a file the compares it to the current time. If greater that 60 mins has gone by and the file has not been written to alert. So far I have the time pulled from the file but I dont know how to compare the times against a 60 min difference. ... (2 Replies)
Discussion started by: jarich
2 Replies
Login or Register to Ask a Question