[ale] cron fun

Jerry Yu jjj863 at gmail.com
Tue Feb 6 08:01:02 EST 2007


You are correct, Robert. Environment variables can be set in 'crontab'. In
fact, the unexpected file name you saw is case in point : the DATE variable
is set and effective. The only surprise is the backtick was not executed.

Here is the excerpt off crontab (5) man page. So, it reads like  only ' and
" are expected for quoting the value string.
An active line in a crontab will be either an environment setting or a
       cron command.  An environment setting is of the form,

           name = value

       where the spaces around the equal-sign (=) are optional, and any
sub-
       sequent non-leading spaces in value will be part of the value
assigned
       to name.  The value string may be placed in quotes (single or
double,
       but matching) to preserve leading or trailing blanks.


On 2/2/07, Robert L. Harris <Robert.L.Harris at rdlg.net> wrote:
>
>
>
>   Well I basically put the whole cron into the script and have a new cron
> file
> which runs the script.  I could have sworn that cron was capable of
> setting
> some variables like this.  Oh well, not the first time I was wrong and I'm
> sure it won't be the last.
>
>
>
>
> Thus spake Chuck Huber (chuck at cehuber.org):
>
> > ale-request at ale.org wrote:
> > > ----------------------------------------------------------------------
> > >
> > > Message: 1
> > > Date: Fri, 2 Feb 2007 12:03:00 -0500
> > > From: "Robert L. Harris" <Robert.L.Harris at rdlg.net>
> > > Subject: [ale] cron fun
> > > To: Atlanta Linux Enthusiasts <ale at ale.org>
> > > Message-ID: <20070202170300.GZ25038 at rdlg.net>
> > > Content-Type: text/plain; charset="us-ascii"
> > >
> > >
> > >
> > > Ok, I've got a cronjob, /etc/cron.d/dumppkgs that reads as such:
> > >
> > >
> > >
> > > ----------------------------------------------------------------------
> > > # /etc/cron.d/php4: crontab fragment for php4
> > > #  This purges session files older than X, where X is defined in
> seconds
> > > #  as the largest value of session.gc_maxlifetime from all your
> php.ini
> > > #  files, or 24 minutes if not defined.  See /usr/lib/php4/maxlifetime
> > > MAILTO=robert at rdlg.net
> > > DATE=`/bin/date +%w`
> > > OUTFILE="/etc/Packages.dump.week."$DATE".txt"
> > >
> > > # Backup dpkg selections
> > > 0 12 * * *     root   /usr/bin/dpkg --get-selections > $OUTFILE
> >
> > Danny is right about cron scripts not being shell scripts.
> > A wrapper is going to be the best bet.  Try something like:
> >
> > savestdout.sh:
> > #/bin/bash
> > DATE=`/bin/date +%w`
> > OUTFILE="/etc/Packages.dump.week."$DATE".txt"
> > # redirect stdout to a file
> > exec >${OUTFILE}
> > # launch the desired program
> > exec "$@"
> >
> > Then in crontab:
> > 0 12 * * * root /full/path/to/savestdout.sh /usr/bin/dpkg
> --get-selections
> >
> > Hope this helps.
> >
> > Enjoy,
> >     - Chuck
> >
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > http://www.ale.org/mailman/listinfo/ale
>
> :wq!
>
> ---------------------------------------------------------------------------
> Robert L. Harris                     | GPG Key ID: E344DA3B
>                                          @ x-hkp://pgp.mit.edu
> DISCLAIMER:
>       These are MY OPINIONS             With Dreams To Be A King,
>        ALONE.  I speak for              First One Should Be A Man
>        no-one else.                       - Manowar
>
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFFw9K/8+1vMONE2jsRArKNAKDfMIbzA8qrKp7v+2UmUUIwliTCxgCgx86v
> 65M6XA1KeL3pBCOGWWjF+24=
> =AAhP
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>
>
-------------- next part --------------
An HTML attachment was scrubbed...




More information about the Ale mailing list