Is there a special restriction on commands executed by cron?

I have crontabone that looks like

0 0 * * * pg_dump DB_NAME > /path/to/dumps/`date +%Y%m%d`.dmp

which works fine when I launch it manually, but not when it cronlaunches it. After digging through the magazines I see

Dec 12 00:00:01 localhost crond[17638]: (postgres) CMD (pg_dump DB_NAME > /path/to/dumps/`date +)

It seems like a problem with percent signs, but the page mandoes not contain a percent character at all, so I thought that everything was in order.

+5
source share
2 answers

You need to avoid percent signs with a backslash:

0 0 * * * pg_dump DB_NAME > /path/to/dumps/`date +\%Y\%m\%d`.dmp

From man 5 crontab:

( )        . , newline %        , /bin/sh ,        SHELL crontab. (%) ,         (\), , %         .         , , , "\".

+10

, , cron ( "%", ).

. , , , , , , , at, , . cron .

, , cron , script , (, $HOME/bin PATH). - script, .

#   @(#)$Id: crontab,v 4.2 2007/09/17 02:41:00 jleffler Exp $
#   Crontab file for Home Directory for Jonathan Leffler (JL)
#-----------------------------------------------------------------------------
#Min     Hour    Day     Month   Weekday Command
#-----------------------------------------------------------------------------
0        *       *       *       *       /usr/bin/ksh /work1/jleffler/bin/Cron/hourly
1        1       *       *       *       /usr/bin/ksh /work1/jleffler/bin/Cron/daily
23       1       *       *       1-5     /usr/bin/ksh /work1/jleffler/bin/Cron/weekday
2        3       *       *       0       /usr/bin/ksh /work1/jleffler/bin/Cron/weekly
21       3       1       *       *       /usr/bin/ksh /work1/jleffler/bin/Cron/monthly

script /work1/jleffler/bin/Cron script /work1/jleffler/bin . cron script.

+3

All Articles