![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
Code:
#!/bin/ksh trap "sleep 1; exit" USR1 script1.shl & #.............your code goes here.......... |
|
#3
|
|||
|
|||
|
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.... |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|