[lug] CRON

rm at mamma.varadinet.de rm at mamma.varadinet.de
Thu Sep 7 16:49:06 MDT 2000


On Thu, Sep 07, 2000 at 05:54:18PM -0500, Michael J. Hammel wrote:
> Thus spoke John Starkey
> > I need to have reminders show up on the screen and some I want emailed. If
> > I write a script to simply echo "whatever I need to say to myself" how
> > would I require a certain keystroke to confirm? ( an IF statement maybe?? 
> > )
> 
> As far as I know you can't do this.  Cron runs without being attached to a
> vt and it can't be told to grab a vt directly - the program you run will
> have to do that.  For example, under X (which I know you don't want) I can
> [...]
> echo "this is a test message"

well, we wouldn't use *NIX if there wheren't ways to do this:
have a look at 'wall(1)' or 'write(1)' on your system.
For example 
  'echo "You should better go to sleep now" write ralf'
will work even if called from the crontab file (but read 
the manpage part about ttys you can specify and the 'mesg'
command).

> 
> causes the output to go into /dev/null from cron.  There isn't any place for 
> cron to display it.

This depends on the version/family of cron you use. Some versions
support the 'MAILTO=bla at fusel.org' directive in the crontab file
(use 'man 5 crontab' to check this).

> Cron is specifically designed to run in the background without user
> interaction, so I think adding user interaction from it is kind of a 
> security violation.  Or at least I think it's generally frowned upon.
> 
> > Is it possible to do this on ttyS[1-6] and have input from one confirm for
> > all the vt's??

... now that's going to be hard :-) Yes,  it should be possible to
do _if_ you run your script as root (please don't) but it might
be highly anoiying. On my first account (on a VMS Vax Cluster) this
was done. I allways got mad when my terminal got messed up with
'new mail arrived' messages while i was writing mail.

> Leave cron out of the picture and ask yourself if you can write a program
> to do this just from your own shell prompt.  The answer is "probably not" -
> at least not easily.  You might be able to do it in Perl.  I'd do it in C.
> Cron just launches programs and doesn't give them access to a terminal
> (display) device.  It really doesn't care too much what the program does.

Well, a (p)tty isn't anything special, just another plain old file.
 bash-2.03$ perl 
 open (USER, ">/dev/pts/1") or die;
 print USER "I'm anoiying \n";
 exit 0;
 ^D

assuming that you work under X and use ptys will do it.
With a little bit more tweaking you _could_ get user responses
as well:
 #!/usr/bin/perl 
  
 use IO::File;
   
 my $tty1 = new IO::File;
 my $tty2 = new IO::File;
    
 $tty1->open("/dev/pts/0", "w")  # open the terminal for r
 $tty2->open("/dev/pts/0", "r")  # open the terminal for w
 $tty1->print("Am i anoiying? > ");
     
 while ($_ = $tty2->getc){
   last if /y/i;
 }
 $tty1->close;
 $tty2->close;
 exit 0;

Note: this won't work! You will need to set the terminal
attributes and grab the input etc. 
But, as Michael allready said: this is probably not a good idea.


 Ralf




More information about the LUG mailing list