- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- time operations
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2005 09:22 PM
06-13-2005 09:22 PM
Are there any expresion to add x seconds to current time ?
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2005 09:35 PM
06-13-2005 09:35 PM
Re: time operations
do you mean adding seconds to the system time? If yes, on 11.00 and onwards you can make the system clock tick faster until it has drifted a specified number of seconds ahead of it' prevoius time, e.g.
# date -a 45
which will slowly adjust the clock by addding 45 seconds.
Beware, that you get a prompt back immediately and you get no indication of when the "drift" has finished.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2005 09:41 PM
06-13-2005 09:41 PM
Re: time operations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2005 09:51 PM
06-13-2005 09:51 PM
Re: time operations
(( now = `date +%H` * 3600 + `date +%M` * 60 + `date +%S` ))
This will set $now to be the time of day in seconds. Add 45 to this to get the time in 45 seconds.
Then if you want to compare "45 seconds time" with eg 18:00:00 (or any arbitrary time) you can calculate the time to compare with:
(( comptime = 18*3600 + 0*60 + 0 ))
Obviously if comparing against fixed times you don't need the formula above in your script just calculate it, but the above formula lets you use hours/minutes/seconds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2005 11:11 PM
06-13-2005 11:11 PM
Re: time operations
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2005 11:16 PM
06-13-2005 11:16 PM
SolutionTry this script:
#!/bin/ksh
H=`date +%H`
M=`date +%M`
SEC=`date +%S`
echo "Time is ${H}:${M}:${SEC}"
let HOUR=${H}*3600
let MIN=${M}*60
let TIME_IN_SECS=${HOUR}+${MIN}+${SEC}
let TIME_IN_SECS=${TIME_IN_SECS}+$1
let NEWHOUR=${TIME_IN_SECS}/3600
ADJ_HOUR=$NEWHOUR
LOOP=TRUE
while [ $LOOP = "TRUE" ]
do
if [ $ADJ_HOUR -gt 23 ]
then
let ADJ_HOUR=$ADJ_HOUR-24
else
LOOP=FALSE
fi
done
let TMPHOUR=$NEWHOUR*3600
let TMPMIN=${TIME_IN_SECS}-$TMPHOUR
let NEWMIN=${TMPMIN}/60
let TMPSEC=${NEWMIN}*60
let NEWSEC=${TMPMIN}-$TMPSEC
typeset -Z2 HOUR=$ADJ_HOUR
typeset -Z2 MIN=$NEWMIN
typeset -Z2 SEC=$NEWSEC
echo "Wound time is ${HOUR}:${MIN}:${SEC}"
Save it to a file, give execute permissions and call it with an argument (e.g. /tmp/myscript 500)
You will need to test though - if the time is wound to a subsequent day, the script won't tell you that, although it does report the time correctly!!
HTH - Keith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2005 11:20 PM
06-13-2005 11:20 PM
Re: time operations
All the best - KB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 02:15 AM
06-14-2005 02:15 AM
Re: time operations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 03:38 AM
06-14-2005 03:38 AM
Re: time operations
$ at -qd now + 3 seconds < JOBS/job1.job
bad date specification
Looking at man at, the time specification seconds is not allowed, only minutes, hours, days.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 03:45 AM
06-14-2005 03:45 AM
Re: time operations
sleep 3
at -f /usr/local/bin/myjob.sh now
to my script.
The "now" by itself is legal syntax for at.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 03:52 AM
06-14-2005 03:52 AM
Re: time operations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 04:29 AM
06-14-2005 04:29 AM
Re: time operations
http://www.bmc.com/products/proddocview/0,2832,19052_19429_23437_1521,00.html
or, have 1 "Master" job - that calls all the other jobs - which waits for each job to finish prior to starting the next one...
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 04:49 AM
06-14-2005 04:49 AM
Re: time operations
CCYYMMDDhhmm.ss
Use it like this:
TM=$(inctime.pl 5)
echo "Time 5 seconds from now = ${TM}"
------------------------------------------
#!/usr/bin/perl -w
use strict;
use integer;
use English;
sub Usage
{
printf STDERR
("Usage: %s inc\n\n",$PROGRAM_NAME);
printf STDERR
("Returns a timestring CCYYMMDDhhmm.ss differing by inc seconds from\n");
printf STDERR
("the current time. Inc may be positive or negative.\n\n");
return(255);
} # Usage
sub Problem
{
my $msg = $_[0];
my $err = $_[1];
printf STDERR ("\n%s: %s (%d)\n",$PROGRAM_NAME,$msg,$err);
return(1);
} # Problem
my $cc = 0;
if ($#ARGV >= 0)
{
if ($ARGV[0] =~ /^[+\-]{0,1}\d+$/)
{
my $inc = $ARGV[0];
my $now = time();
my ($seconds,$minutes,$hours,$mday,$month,$year,$wday,$yday,$isdst)
= localtime($now + $inc);
printf("%04d%02d%02d%02d%02d.%02d\n",$year + 1900,$month + 1,
$mday,$hours,$minutes,$seconds);
}
else
{
$cc = 254;
my $s_err = sprintf("Invalid increment '%s'",$ARGV[0]);
Problem($s_err,$cc);
}
}
else
{
$cc = Usage();
}
exit($cc);
------------------------------------------
If I didn't make any booboo's that should be it and I made it accept positive or negative or zero increments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 07:35 AM
06-14-2005 07:35 AM
Re: time operations
I work with first shell script posted by Keith Bryson beacause when the perl script was posted I was working with it and I don't know how perl scripts works for receive external varibles and and this is the result:
I have a script for rescheduling queued jobs named personal_rescheduling.sh:
Hour=`date +'%H'`
Minute=`date +'%M'`
Second=`date +'%S'`
jobs_dir="/var/spool/cron/atjobs/"
ls -1 $jobs_dir | while read job_name
do
execution_hour=`add_seconds.sh 3 $Hour $Minute $Second`
at -qd -t $execution_hour < $jobs_dir$job_name
if [ $? = 0 ]
then
at -r $job_name
fi
Hour=`add_seconds.sh 3 $Hour $Minute $Second | cut -c 9-10`
Minute=`add_seconds.sh 3 $Hour $Minute $Second | cut -c 11-12`
Second=`add_seconds.sh 3 $Hour $Minute $Second | cut -c 14-15`
done
This script reschedule all queued jobs from now every 3 seconds.
The script used add_seconds.sh is the one posted by Keith Bryson only changed for accept time externaly:
#!/usr/bin/sh
#
# Using: add_seconds.sh seconds_to_add hour minute second
# Return: date and time in at format CCYYMMDDhhmm.ss
#
H=$2
M=$3
SEC=$4
## Lines commented and rewrited beacause when hour, minute or second is 08 or 09 this sentence return error.
#let HOUR=${H}*3600
#let MIN=${M}*60
#let TIME_IN_SECS=${HOUR}+${MIN}+${SEC}
#let TIME_IN_SECS=${TIME_IN_SECS}+$1
#let NEWHOUR=${TIME_IN_SECS}/3600
HOUR=`expr ${H} \* 3600`
MIN=`expr ${M} \* 60`
TIME_IN_SECS=`expr ${HOUR} + ${MIN} + ${SEC}`
TIME_IN_SECS=`expr ${TIME_IN_SECS} + $1`
NEWHOUR=`expr ${TIME_IN_SECS} \/ 3600`
ADJ_HOUR=$NEWHOUR
LOOP=TRUE
while [ $LOOP = "TRUE" ]
do
if [ $ADJ_HOUR -gt 23 ]
then
let ADJ_HOUR=$ADJ_HOUR-24
else
LOOP=FALSE
fi
done
let TMPHOUR=$NEWHOUR*3600
let TMPMIN=${TIME_IN_SECS}-$TMPHOUR
let NEWMIN=${TMPMIN}/60
let TMPSEC=${NEWMIN}*60
let NEWSEC=${TMPMIN}-$TMPSEC
typeset -Z2 HOUR=$ADJ_HOUR
typeset -Z2 MIN=$NEWMIN
typeset -Z2 SEC=$NEWSEC
execution_date=`date +%Y%m%d`
echo "${execution_date}${HOUR}${MIN}.${SEC}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 07:35 AM
06-14-2005 07:35 AM
Re: time operations
I make a script for scheduling jobs like in HP3000 (I recently migrated from this platform), and I called it stream.sh
DIMPSG_HOME="/homes/dimpsg"
ORA_HOME="/homes/oracle"
JOBFI="$DIMPSG_HOME/CONFIG/personal_rescheduling.sh"
if [ "$2" = "-oracle" ]; then
JOBINI="$ORA_HOME/$1.job"
else
JOBINI="$DIMPSG_HOME/JOBS/$1.job"
fi
if [ -f $JOBINI ]; then
cat $JOBINI $JOBFI > arxiutmp
at -qd now < arxiutmp
rm arxiutmp
else
echo "El job que intentes llençar no existeix !!! BUUURROOOOOO. Anónimo"
fi
With this script I append at end of every job the personal_rescheduling.sh script and queue it. Every time a job finishes, it reschedule the rest of queued jobs to grant correct execution order.
Like in HP3000, I make a script to change the job's limit for the queue, obiously I call it limit.sh:
#!/usr/bin/sh
SUDOBIN=/opt/sudo/bin/sudo
COMUSUARI="root"
JLIMIT="$1"
PRI="0"
CONFDIR="/homes/dimpsg/CONFIG"
if [ $1 ]
then
case $1 in
0 ) QUEFEM="stop"
$SUDOBIN -S -i -u $COMUSUARI $HOME/CONFIG/Squeue.sh $QUEFEM $JLIMIT $PRI;;
[1-5] ) QUEFEM="start"
$CONFDIR/personal_rescheduling.sh
$SUDOBIN -S -i -u $COMUSUARI $HOME/CONFIG/Squeue.sh $QUEFEM $JLIMIT $PRI;;
* ) echo "El lÃmit ha d'estar entre 0 i 5 marica!! NO HI HA MÃ S LLICÃ NCIES";;
esac
else
echo "M'INVENTO EL LIMIT QUE VOLS POSAR?, ES QUE....?"
fi
When argument is 0 I stop the queue and when argument between 1 and 5 (max limit for my queue) I reschedule all jobs for grant execution in correct order and start the queue with Squeue.sh script:
#! /usr/bin/sh
#cua a arrancar-parar,nombre de jobs,prioritat
cd /var/adm/cron
OLD_LIMIT=`cat queuedefs | grep "^d."`
NEW_LIMIT=d.$2j$3n2w
sed -e 's/'$OLD_LIMIT'/'$NEW_LIMIT'/' queuedefs >queuedefsold #falla
mv queuedefsold queuedefs
chmod 664 queuedefs
chown bin:bin queuedefs
This script only change the job limit for queue d.
I'm sure there is a so easy way to do all I explain here, but I'm new in HP-UX and I'm so happy this works fine.
Thank you so much!!
Especial thanks to Pere Vidal i
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 06:42 PM
06-14-2005 06:42 PM
Re: time operations
Glad we could help. Are you finished with this thread now? If so, can you allocate some points to all our responses and close it down. If you need any more help, let us know.
All the best - Keith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 07:32 PM
06-14-2005 07:32 PM