The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Get date and time for past 1 hour from current date spch2o Shell Programming and Scripting 5 08-29-2008 01:32 AM
Time difference Segwar Shell Programming and Scripting 4 07-21-2008 08:48 PM
Processing a log file based on date/time input and the date/time on the log file primp Shell Programming and Scripting 4 03-16-2008 08:23 AM
NTP - with time difference shauche AIX 0 07-01-2007 10:21 PM
time difference decci_7 UNIX for Advanced & Expert Users 3 10-09-2006 12:57 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-07-2008
Registered User
 

Join Date: Oct 2007
Posts: 61
Date and time difference

Hi,

I am starting a process at 9 pm today and want to exit the process by 5am, the next day. Every day at 9pm the shell script will be invoked by autosys.
But how can i monitor in my script for 5 am and stop the process ?

there may be a case where the script can start at 4.59 am and complete by even 6.00 am. So checking for (if current time >= 5 am ) will also wont work. Is there any function like date_diff or something else ?? How this can be acheived.


Risshanth
Reply With Quote
Forum Sponsor
  #2  
Old 10-07-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
You want the script to stop itself after 8 hours or 28800 seconds. Here is one somewhat clunky way -
Code:
#!/bin/ksh
#  script1.shl
secs()
{
   perl -e 'print time;'
}
start=$(secs)
stoptime=$(( start + 28800))
now=$(secs)
while [[ $now -lt stoptime ]]
do
      sleep 1
      now=$(secs)
done
kill -USR1 $PPID
exit
main script
Code:
#!/bin/ksh
trap "sleep 1; exit" USR1 
script1.shl &

#.............your code goes here..........
Reply With Quote
  #3  
Old 10-07-2008
Registered User
 

Join Date: Oct 2007
Posts: 61
Hi

The time calculating stuff i clear. What does the following does:

trap "sleep 1; exit" USR1 in the main code.

Please explain this in detail.

Thanks....
Reply With Quote
  #4  
Old 10-07-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
When the child process gets past the time barrier it sends a SIGUSR1 to the parent. The trap in the parent grabs the signal (trap) sleeps long enough for the child to exit, then exits itself.

trap "command[s] to execute" signalname

to see all signals for your system try
Code:
kill -l
the -l is a lowercase L
Reply With Quote
  #5  
Old 10-07-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
If you are using ksh93, you can use the alarm mechanism to simplify coding as shown in the following simple example
Code:
!#/usr/bin/ksh

# abort after 10 seconds
alarm -r timedout +10

timedout.alarm()
{
    print "Exceeded allowed time.  Aborting script ........"
    kill -9 $$
}

read dummy         # dummy wait - press ENTER to exit
exit 0
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0