Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scheduling Script (date/time) Help Please

Status
Not open for further replies.

Exie

Programmer
Sep 3, 2003
156
AU
Hi,

We have a batch queue processing system where we can submit jobs from the command line.

In my script, I want to schedule a job to run 1Hr from the current time. The syntax for our queue system is:
[blue]<queue master binary> -start dd/mm/yyyy.hh:mm[/blue]

I know I can use:
[blue]CURDATE=`date "+%d/%m/%Y.%X"`[/blue]

to give me the current date/time in the right format, but how can I increment it by 1 hr ?

I thought about using something like:
[blue]CURHOUR=`date "+%d/%m/%Y.%X" | cut -c 12-13`
NEW=`expr $CURHOUR + 1`
[/blue]

But this wont account for things rolling past midnight (23:30 +1 = 24:30 ... invalid!).
 
man at (the now + syntax)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV,

Although I'm not using AT (our Unix admins have disabled it). Our batch processing system is called BQ+, unfortunately, I dont think it supports that syntax.
 
Try to play with the TZ variable when grabing the current date.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
If you have some systematic script that's running all the time executing jobs so not using at(1), you could have a small account(sleep time, job, params) setting sleeping time like '1h', which like could be gotten as '+1h' or '-start 1h' arg, or differential extracted from a date.

Code:
account() { local sleep=$1 prog=$2; shift 2
  #sleep=`expr $sleep + 1`
  echo "waiting $sleep to start '$prog $@'"; sleep $sleep
  if [ -z "$1" ]; then
    $prog
  else
    $prog "$@"
  fi
}

dsdiff() { local new=$1 src=$2 num; [ -z "$src" ] && src=$(date +%s)
  num=$(expr $new - $src)
  (( num < 0 )) && expr $src - $new || echo $num
}

a_job() { echo job done >>/tmp/jobtest; }

account $(dsdiff $(date -d "12 mins" +%s)) a_job &
account 1m echo 1 minute job done &

the account jobs may also be spawned with output file control and simple max-threads support by another (bash) script on the fly or via self implentation.

. Mac for productivity
.. Linux for developement
... Windows for solitaire
 
Thanks XMB,

Sleep isnt a bad idea, I've patched my script up to use this. basically, I want the same script to execute every hour.

It's not nice bypassing our standard job system, but it looks like it's working this way ... Thanks!
 
just be aware that 'date -d' is GNUism and is not available in most stock OSs.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
here's something to think about:

Code:
#!/bin/ksh

# here's my current EPOCH time
currentEpoch=$(/usr/bin/truss /usr/bin/date 2>&1 | /usr/bin/awk '/^time/ {print $NF}')

# here we convert EPOCH back to human readable format
back2Human=$(echo "0t${currentEpoch}=Y" | usr/bin/adb)

now..... adding 1hour [3600 seconds] to the current time [in epoch] and putting "back2Human" in the proper format are left as homework assignment [wink]

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
To implent looping into account.. recursive restarting w/o much changing, not the best way though. Can surely be done shorter.
Code:
account() { local sleep=$1 prog=$2 do_loop; export loop everloop; shift 2
  [ ${loop=0} -gt 0 ] && do_loop=1 # || do_loop=0
  [ -z $prog ] && { echo no program to account >&2; return 1; }
  [ -z $sleep ] && sleep=0
  [ -z $everloop ] && { echo -n "waiting $sleep to start '$prog $@'" >&2
    [ ! -z $do_loop ] && echo ", looping $loop times" || echo
  }
  sleep $sleep || return 1

  [ ! -z $do_loop ] && { [ -z $everlast ] && everlast=1 # doesnt work?
    loop=`expr $loop - 1`
  }

  if [ -z "$1" ]; then
    $prog
  else
    $prog "$@"
  fi

  #(( toloop >0 )) && loop=`expr $toloop - 1` account $sleep $prog "$@" &
  [ $loop -gt 0 ] && everloop=1 account $sleep $prog "$@" #&
}

# with the sideeffect of looping once too much
loop=4 account 2 echo slept 2

Do you have to address any maximum alive job count?

. Mac for productivity
.. Linux for developement
... Windows for solitaire
 
vlad, truss was what, freebsd? Whats the few times seen adb?

awk '/^time/ { print $NF; exit }' # may do better
 
Thanks for TZ tip PHV,

I've looked all over the web for some examples, but they are few. I did however read a number of people recomending against it.

The TZ technique is described as "Playing with the TZ variable isn't a reliable method."

... but I did find some other funky code to convert to/from Julian dates, but it's a decent chunk of code, for what I want I think the sleep provides the quickest, simplest solution ....
 
xmb,
that was Solaris-based sample - not sure about the others!


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks again guys,

I do like the code from Vlad, it looks quite compact and neat, however I ran it on our HPUX and with no success.

We dont have truss or adb, so I tried the following:
[blue]/usr/bin/date 2>&1 | /usr/bin/awk '/^time/ {print $NF}'[/blue]

But this didn't produce any output (I'm not that into awk sorry).

None the less, the sleep method is working pretty well.
 
Cheer0s,
truss is something like strace on linux, show system calls. vlad's code is intended to extract the time off time*() called system functions by date, not the date output itself.

. Mac for productivity
.. Linux for developement
... Windows for solitaire
 
whatis adb
adb adb (1) - general-purpose debugger

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
If you have access to perl here's a neat perl solution to the time in one hour problem which is to get the time in seconds since the epoch, add 60 * 60 and convert it to whatever format. An example that does NOT give what what you want but demonstrates the principle is
Code:
perl -e 'my $now = time; $now += ( 60 * 60 ); print scalar localtime ( $now );'
[code]
The perl gurus on the perl forum can help tidy it up and get the formatting right.

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top