[comp.unix.questions] Use the time in a script?

ce1zzes@prism.gatech.EDU (Eric Sheppard) (09/27/90)

I would like to make sure that a script or program is not executed during
a certain period of every hour.  Is there an elegant method to achieve this,
short of an additional C program?

Eric

merlyn@iwarp.intel.com (Randal Schwartz) (09/28/90)

In article <14183@hydra.gatech.EDU>, ce1zzes@prism (Eric Sheppard) writes:
| I would like to make sure that a script or program is not executed during
| a certain period of every hour.  Is there an elegant method to achieve this,
| short of an additional C program?

If you can blow off the positional args:

set -- `date`
case $4 in
	*:0[0-4]:* )
		echo "Bad time to run this"
		exit 1;;
esac

If you can't, you'll need to save and restore them, or run this in a
subshell (within parens) and check the exit status.

Just another sh hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

subbarao@phoenix.Princeton.EDU (Kartik Saligrama Subbarao) (09/28/90)

In article <14183@hydra.gatech.EDU> ce1zzes@prism.gatech.EDU (Eric Sheppard) writes:
>I would like to make sure that a script or program is not executed during
>a certain period of every hour.  Is there an elegant method to achieve this,
>short of an additional C program?
>
>Eric


How 'bout this:

#! /bin/csh -f
mv filename filename.dontusenow
sleep 3000
mv filename.dontusenow filename

# If more is required, then perhaps a chmod 000 filename, or a message printed when the
# file is executed?

				-Kartik

(I need a new .signature -- any suggestions?)
subbarao@{phoenix or gauguin}.Princeton.EDU -|Internet
kartik@silvertone.Princeton.EDU (NeXT mail)       -|	
SUBBARAO@PUCC.BITNET			          - Bitnet

cpcahil@virtech.uucp (Conor P. Cahill) (09/28/90)

In article <14183@hydra.gatech.EDU> ce1zzes@prism.gatech.EDU (Eric Sheppard) writes:
>I would like to make sure that a script or program is not executed during
>a certain period of every hour.  Is there an elegant method to achieve this,
>short of an additional C program?

How about by using the date(1) command.  The following shell will exit
if it is between 10 and 15 minutes past the hour (inclusive).

	start=10
	end=15
	time=`date +%M`

	if [ $time -ge $start -a $time -le $end ]; then
		echo "you can't do this now"
		exit
	fi

	echo ok to run

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 

rick@tetrauk.UUCP (Rick Jones) (09/28/90)

In article <14183@hydra.gatech.EDU> ce1zzes@prism.gatech.EDU (Eric Sheppard) writes:
>I would like to make sure that a script or program is not executed during
>a certain period of every hour.  Is there an elegant method to achieve this,
>short of an additional C program?

The "date" command can be made to give you any selected date or time info with
a format string.  e.g. date +%M prints the minutes (check-out the man page!).

Thus to block operation between say 20 & 40 mins past each hour:

	minmins=20 maxmins=40

	mins=`date +%M`
	if expr $mins \> $minmins \& $mins \< $maxmins > /dev/null
	then
		echo No dice
		exit 1
	fi

Adjust the logic to suit.

-- 
Rick Jones			The definition of atomic:
Tetra Ltd.				from the Greek meaning "indivisible"
Maidenhead, Berks, UK		So what is:
rick@tetrauk.uucp			an atomic explosion?

gwyn@smoke.BRL.MIL (Doug Gwyn) (09/30/90)

In article <14183@hydra.gatech.EDU> ce1zzes@prism.gatech.EDU (Eric Sheppard) writes:
-I would like to make sure that a script or program is not executed during
-a certain period of every hour.  Is there an elegant method to achieve this,
-short of an additional C program?

Sure -- have "cron" disable the "x" bits during the requisite periods.

gt0178a@prism.gatech.EDU (JIM BURNS) (09/30/90)

in article <13974@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn) says:
> Sure -- have "cron" disable the "x" bits during the requisite periods.

Good lord, talk about brute force. :-)
-- 
BURNS,JIM
Georgia Institute of Technology, Box 30178, Atlanta Georgia, 30332
uucp:	  ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt0178a
Internet: gt0178a@prism.gatech.edu