Constraints for getting commands executed by cron

0 votes

Why does my crontab work fine when I run it manually, but not when cron runs it. The following is what my crontab looks like:

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

After going through all logs, here's what I found: 

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

As far as I can understand, it seems as though there is a problem involving some percent signs. However, I don't really have a single percentage character all throughout my man page. Could anyone tell me what's actually wrong or what's going on in here?

Nov 14, 2018 in Linux Administration by Bharani
• 4,550 points
19 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

I think the problem could be those percent signs in your crontab that you did not escape using a backslash, which you should do. So, change it into something like this(check man page also):

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

Check this out;

From man 5 crontab:
The ‘‘sixth’’ field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file. Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the shell’s trailing "\".

answered Nov 14, 2018 by nirvana
• 3,040 points

Related Questions In Linux Administration

0 votes
1 answer
0 votes
1 answer

How to use help command for ls?

The help command is limited and it ...READ MORE

answered Jan 3 in Linux Administration by Omkar
• 65,840 points
82 views
0 votes
1 answer

How to check version of package installed by npm?

These commands are used to check the ...READ MORE

answered Feb 4 in Linux Administration by Omkar
• 65,840 points
52 views
0 votes
1 answer

Making a program sleep for milliseconds?

There are no standard C API's that ...READ MORE

answered Mar 1 in Linux Administration by DareDev
• 6,520 points
14 views
0 votes
1 answer

Error: dpkg frontend is locked by another process

First run: lsof /var/lib/dpkg/lock Then make sure that process ...READ MORE

answered Apr 1 in Linux Administration by Shir
181 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How do I set variable if a specific package version is installed in CFEngine?

Here is what you can do.Just use packagesmatching to ...READ MORE

answered Jul 12, 2018 in Other DevOps Questions by Atul
• 10,200 points
47 views
0 votes
1 answer

How to run Unix shell script from Java code?

ProcessBuilder pb = new ProcessBuilder("myshellScript.sh", "myArg1", "myArg2"); ...READ MORE

answered Oct 26, 2018 in Java by Daisy
• 8,020 points
50 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.