[lug] cron question

Walter Pienciak walter at frii.com
Tue Oct 24 18:05:40 MDT 2000


On Tue, 24 Oct 2000, Michael Wegener wrote:

> Thanks Bill and Walter,
> 
> By specifying the full path, I can get sitecopy to run (which is the critical
> one), however using the full path for echo still shows nothing. Apparently,
> the output for cron is redirected to /dev/null or something like that, since I
> see no output for anything run by cron. The only generic config file I can
> find is /etc/crontab, which is where you set the SHELL and PATH vars. But I
> see nothing that would redirect output. Any ideas? True, I'll live if I can't
> post reminders to myself to change out the DAT, (I should remember anyway),
> but I *must know*...
> 
> --M
> 
> Bill Jorgensen wrote:
> 
> > On Tue, 24 Oct 2000, Walter Pienciak wrote:
> >
> > > Summary: Either use full pathnames for your executables or man cron to
> > > see which file you can set cron's environment from, so they *are* in
> > > cron's $PATH.  The first is a lot easier.  The second is a good thing to
> > > know.
> > >
> > > Walter
> >
> > Agreed. I have also exported a PATH variable in the scripts that I write
> > for cron.
> >
> > Bill Jorgensen

I'm not sure what you're describing with echo -- I guess I'd have to see
the script.  Typically, if there's output and it's not being redirected
somewhere, cron e-mails the user the output.  But since I don't have a 
specific answer, I'll just blather generally a bit here.

1. I administrate some large systems with all kinds of add-ons.  One tool
   that keeps me from going insane is having the following line in root's
   cron, run however often:

   find / -ls | grep -v \/cache\/ | /opt/gnu/bin/gzip -9 > /find-ls.txt.gz

   (oh yeah, a good mix of thingies in and not in cron's $PATH.  Anyway...)

   Then when I want to find things on the system, a simple 

   zgrep $pattern /find* 

   (lazy typing) digs it out for me.  You might find some other cron stuff
   buried here and there.  Example, I have a /var/cron/log file.

   You can try 

   find / -ls | grep cron

   (That was my German-construct example, with the important part last.)

2. You can do all kinds of funky things with cron output:

   /usr/local/bin/myscript > dev/null
   /usr/local/bin/myscript > dev/null 2>&1
   /usr/local/bin/myscript | mailx -s "myscript output" me at mycompany.com
   [ -f /core ] && ( rm -f /core && echo "Removed fscking /core" )

3. Sometimes it's just easier to have the script do it internally than
   trying to figure out how to get cron to do it.  Besides, those cron
   lines can get pretty long and ugly.

   cron:
     /home/wpiencia/bin/nudge

   nudge:
     #!/bin/sh

     nudgees="frick at mycompany.com frack at mycompany.com moe at mycompany.com"
     mail="/usr/ucb/mail"
     subject="Automated Reminder:  I need your weekly report."

     for name in `echo $nudgees`
       do
         $mail -s "$subject" $name </dev/null
       done

     $mail -s "Automated Reminders:  SENT" me at mycompany.com </dev/null



Anyway, I hope there's an idea in here somewhere for you.

Walter







More information about the LUG mailing list