[comp.unix.questions] Periodic execution of a program

rawdon@rex.cs.tulane.edu (Michael Rawdon) (01/24/91)

I'm trying to get a program to run on a daily basis, at the same time each
day (more or less).  Being just a normal user, I don't have access to
crontab.  I was investigating a function called 'at', but it doesn't seem
to be quite what I want.

From the man page, it appears that at will only execute something once,
not every day.  I infer this from the fact that the man page doesn't explain
how to turn at off!

I was wondering if it would be possible to execute at recursively, that is,
have the file that at executes call at again to execute the same file at
the same time the next day.  I'm not sure if this would be possible.

Of course, it may be that I just don't have a clue as to which system
utilities I should be using to accomplish my objective.  Any help anyone can
provide would be most welcome.

I'm on a Pyramid 9815 running BSD 4.3 UNIX.

Thanx!

rawdon@rex.cs.tulane.edu (Michael Rawdon) (01/24/91)

I'm trying to get a program to run on a daily basis, at the same time each
day (more or less).  Being just a normal user, I don't have access to
crontab.  I was investigating a function called 'at', but it doesn't seem
to be quite what I want.

From the man page, it appears that at will only execute something once,
not every day.  I infer this from the fact that the man page doesn't explain
how to turn at off!

I was wondering if it would be possible to execute at recursively, that is,
have the file that at executes call at again to execute the same file at
the same time the next day.  I'm not sure if this would be possible.

Of course, it may be that I just don't have a clue as to which system
utilities I should be using to accomplish my objective.  Any help anyone can
provide would be most welcome.

I'm on a Pyramid 9815 running BSD 4.3 UNIX.

Thanx!

-- 
Michael Rawdon						      Someone who posts
Tulane University, New Orleans, Louisiana		       too much for his
Internet: rawdon@rex.cs.tulane.edu			              own good.
Bitnet: CS6FECU@TCSVM

"And they said we were heroes, they said we were fine.
 We were kings in command, we had god on our side,
 And we said nothing will make use change in any way."   - Chris De Burgh

pfalstad@phoenix.Princeton.EDU (Paul Falstad) (01/24/91)

rawdon@rex.cs.tulane.edu (Michael Rawdon) wrote:
>I'm trying to get a program to run on a daily basis, at the same time each
>day (more or less).  Being just a normal user, I don't have access to
>crontab.  

On our system, at least, there is a command called 'crontab' which lets
ordinary users submit crontabs to be run by cron.  Do a "man 1 crontab".

			 I was investigating a function called 'at', but it doesn't seem
>to be quite what I want.
>From the man page, it appears that at will only execute something once,
>not every day.  I infer this from the fact that the man page doesn't explain
>how to turn at off!

at -r <jobnum> will remove a job from the queue, and at -l will list
the current jobs.

>I was wondering if it would be possible to execute at recursively, that is,
>have the file that at executes call at again to execute the same file at
>the same time the next day.  I'm not sure if this would be possible.

Yeah, exactly.  If the crontab doesn't work, try this:

% cat /tmp/bar
foo | sort | mail foo@bar.Berkeley.EDU   # do stuff here
...
at now + 1 day /tmp/bar  # reschedule job
% at (whenever) /tmp/bar
job 64918 at Wed Jan 23 22:37:00 1991

at will execute /tmp/bar every day.

--
Paul Falstad, pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD
In the heat of composition I find that I have inadvertently allowed
myself to assume the form of a large centipede.  I am accordingly
dictating the rest to my secretary.
409 shift/reduce, 62 reduce/reduce conflicts.  Beat that!

guy@auspex.auspex.com (Guy Harris) (01/25/91)

>On our system, at least, there is a command called 'crontab' which lets
>ordinary users submit crontabs to be run by cron.

I infer from the fact that he said "BSD 4.3" that he's running inside
the BSD universe on his Pyramid, so I don't think the "crontab" command
is accessible by default.  "att crontab" might work, as S5R2 and later
do have that "crontab" mechanism.

>at -r <jobnum> will remove a job from the queue, and at -l will list
>the current jobs.

"atrm" and "atq" respectively would, I assume, be the versions in the
BSD universe, those being the BSD flavor of those functions.

mike@bria.UUCP (Michael Stefanik) (01/26/91)

In article <5829@rex.cs.tulane.edu> rex.cs.tulane.edu!rawdon (Michael Rawdon) writes:
>I'm trying to get a program to run on a daily basis, at the same time each
>day (more or less).  Being just a normal user, I don't have access to
>crontab.  I was investigating a function called 'at', but it doesn't seem
>to be quite what I want. [...]

Well, then tell your admin to get off his butt and either put you in
/usr/lib/cron.allow, or touch /usr/lib/cron.deny.  This will convince cron
that you are allowed to have cron jobs executed on your behalf (personally,
I find it a tad apalling that you don't have the permission to create a
crontab).

Once that's done, you can submit a list of commands to be executed using
the crontab(1) command.

Now, if your admin is a jerk, and doesn't think that users have any business
with cron, you could write a little script, such as:

---[ cut here ]-------------------------------------------------------------

trap '' 1 2 3 15

cmd=$1
shift
args="$*"

set `who am i`
user=$1

while :
do
	minute=`date +%M`
	sleep `expr \( 60 - $minute \) \* 60`
	while [ `date +%H` != 1 ]
	do
		sleep 3600
	done
	$cmd $args </dev/null 2>&1 | mail $user
done

---------------------------------------------------------------------------

So, if you wanted to do a tar backup of /u every morning, you would
simply enter the name of script (let's call it not.cron) followed by
the command in question, such as:

	$ not.cron tar cvf /u &

This would run until the system was rebooted, or someone killed it.

-- 
Michael Stefanik, Systems Engineer (JOAT), Briareus Corporation
UUCP: ...!uunet!bria!mike
--
technoignorami (tek'no-ig'no-ram`i) a group of individuals that are constantly
found to be saying things like "Well, it works on my DOS machine ..."

guy@auspex.auspex.com (Guy Harris) (01/27/91)

>Well, then tell your admin to get off his butt and either put you in
>/usr/lib/cron.allow, or touch /usr/lib/cron.deny.  This will convince cron
>that you are allowed to have cron jobs executed on your behalf (personally,
>I find it a tad apalling that you don't have the permission to create a
>crontab).

I agree, but that's a deficiency of the traditional UNIX "cron"
mechanism, which was fixed by, among others, the S5R2 "cron" - the old
system had only *one* "crontab" file, in "/usr/lib/crontab", and all
jobs from that were run as "root" (you had to do an "su" to run them as
somebody else) so it wasn't generally available.

Since the guy was using a Pyramid, it could have either - or perhaps
both! - the BSD "cron" and the S5R2-or-later-S5 "cron"; when he said he
"[didn't] have access to crontab", I'm not sure whether he meant he
didn't have access to the "crontab" *file* (i.e., the BSD "cron"), or
didn't have access to the "crontab" *command* (i.e., the S5 "cron").

If the former, he'd have to ask the administrator to turn on the S5
"cron", and if he runs in the BSD universe, do "att crontab" and
remember that his "cron" job will run in the AT&T universe.

If the latter, he should complain to his system administrator and ask
that they set up the files you mention to let them use "crontab".

udparmet@mcs.drexel.edu (Daniel J. Parmet) (01/28/91)

In article <5830@rex.cs.tulane.edu> rawdon@rex.cs.tulane.edu (Michael Rawdon) writes:
>
>I was wondering if it would be possible to execute at recursively, that is,
>have the file that at executes call at again to execute the same file at
>the same time the next day.  I'm not sure if this would be possible.

I haven't worked with crons in a while, but I believe that what you are trying
to do should work.  When the runstream goes off, your file gets taken out of
cron.  But you can simply have an at command in your run to put the file back
into cron.  I'd be interested in finding out what happens, since my shell
programming is a little rusty, and I may start up with it again soon.  Let me
know.  Thanks.

Dan Parmet (udparmet@queen.mcs.drexel.edu)

"Have you noticed that the longer you spend looking for something you lost, the
 stanger the places get that you're looking?"

                                   ----- George Carlin

frechett@spot.Colorado.EDU (-=Runaway Daemon=-) (01/29/91)

In article <1991Jan28.153105.2996@mcs.drexel.edu> udparmet@mcs.drexel.edu (Daniel J. Parmet) writes:
>>I was wondering if it would be possible to execute at recursively, that is,
>>have the file that at executes call at again to execute the same file at
>>the same time the next day.  I'm not sure if this would be possible.

Just to be sure.. it does work and I am doing it now.. Right after this 
discussion started, I rushed out and looked at "at".  
Cron checks crontab every minute and in our crontab, it says to execute
atrun at 00, 15, 30, and 45 minutes after the hour every hour.  It is 00 and
30 on one of our other machines.  Let me show you what I have running now.
There are two files.  cron123 and cron4
---------cron123--------
CheckServ
---------end cron123----
---------cron4---------
CheckServ
set blue = `date +%H | awk '{print $1 + 1}'`
if ( "$blue" == "24" ) set blue = 0
at ${blue}:00 /users/en-ecen/frechett/IRC/admin/cron123
at ${blue}:15 /users/en-ecen/frechett/IRC/admin/cron123
at ${blue}:30 /users/en-ecen/frechett/IRC/admin/cron123
at ${blue}:45 /users/en-ecen/frechett/IRC/admin/cron4
--------end cron4-------

It is pretty self-explanitory but let me explain anyway.  Lets say that it is
12:44 and I have nothing set up yet.  All I have to do is:
at 12:45 cron4       and it will put cron4 in 
/usr/spool/at/91.027.1245.<some num>
at 12:45 cron does an atrun and atrun checks executes cron4.  cron4 
executes the command CheckServ (This checks to see if a server that I have is
runing and if not, restarts it) and then it checks the current time and adds
one hour to the hh in `date`.  It then goes about setting up the files to 
execute for the next hour.  It sets up cron123 for 1:00 1:15 1:30 and 
cron4 again at 1:45.

The whole cylce is repeated every hour forever.  (note, it does check to see if
it is 23:45)
This setup has been running for several days now...at least since I first saw a
message mentioning "at".  

Hope someone can use this information.

	ian
--

-=Runaway Daemon=-

rembo@unisoft.UUCP (Tony Rems) (01/30/91)

In article <1991Jan28.153105.2996@mcs.drexel.edu> udparmet@mcs.drexel.edu (Daniel J. Parmet) writes:
>In article <5830@rex.cs.tulane.edu> rawdon@rex.cs.tulane.edu (Michael Rawdon) writes:
>>
>>I was wondering if it would be possible to execute at recursively, that is,
>>have the file that at executes call at again to execute the same file at
>>the same time the next day.  I'm not sure if this would be possible.
>
>I haven't worked with crons in a while, but I believe that what you are trying
>to do should work.  When the runstream goes off, your file gets taken out of
>cron.  But you can simply have an at command in your run to put the file back
>into cron.  I'd be interested in finding out what happens, since my shell
>programming is a little rusty, and I may start up with it again soon.  Let me
>know.  Thanks.
>

Just about every man page I've seen for the at command has the following
in it:

   BUGS
        Due to the granularity of the execution of /usr/lib/atrun,
        there may be bugs in scheduling things almost exactly 24
        hours into the future.
   

This includes SunOS, Pyramid, Vax, and a number of others.  You 
may run into this problem.

-Tony
   
   

guy@auspex.auspex.com (Guy Harris) (01/31/91)

 >Just about every man page I've seen for the at command has the following
 >in it:
 >
 >   BUGS
 >        Due to the granularity of the execution of /usr/lib/atrun,
 >        there may be bugs in scheduling things almost exactly 24
 >        hours into the future.
 >   
 >This includes SunOS, Pyramid, Vax, and a number of others.  You 
 >may run into this problem.

It's missing from the AT(1) man page on the SunOS 4.0.3 machine on which
I'm typing this.  Part of the reason for that is that SunOS 4.x uses the
S5 "cron"/"at" package, which doesn't *HAVE* "/usr/lib/atrun"; instead,
"cron" runs both "cron" and "at" jobs, rather than "/usr/lib/atrun"
being run every 15 minutes or whatever out of "crontab".

pfalstad@phoenix.Princeton.EDU (Paul Falstad) (02/13/91)

rawdon@rex.cs.tulane.edu (Michael Rawdon) wrote:
>I'm trying to get a program to run on a daily basis, at the same time each
>day (more or less).  Being just a normal user, I don't have access to
>crontab.  I was investigating a function called 'at', but it doesn't seem
>to be quite what I want.

Didn't I see this article posted a few weeks ago?  I've seen articles in
other groups (including the "void function pointers" question in
comp.lang.c) that look very familiar; I think they are reposts.  What
could be causing this?

--
Paul Falstad, pfalstad@phoenix.princeton.edu | 10 PRINT "PRINCETON CS"
[Your blood pressure just went up.]          | 20 GOTO 10
Princeton University would like to apologize to everyone for this article.
            "It seems inappropriate to use comp.unix.wizards
             as an AI interface to TFM."  - Tom Christiansen