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,560 points
110 views

1 answer to this question.

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,060 points

Related Questions In Linux Administration

0 votes
1 answer
–1 vote
1 answer

How to use help command for ls?

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

answered Jan 3, 2019 in Linux Administration by Omkar
• 69,040 points
1,005 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, 2019 in Linux Administration by Omkar
• 69,040 points
374 views
0 votes
1 answer

Making a program sleep for milliseconds?

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

answered Mar 1, 2019 in Linux Administration by DareDev
• 6,850 points
75 views
+2 votes
5 answers

Error: dpkg frontend is locked by another process

First, find out the id of the process that ...READ MORE

answered Aug 7, 2019 in Linux Administration by Sirajul
• 54,240 points
46,415 views
0 votes
1 answer

Which is a good hex editor for Linux?

You could try Bless. It is written ...READ MORE

answered Jun 4, 2019 in Linux Administration by Upasana
• 8,590 points
84 views
0 votes
1 answer
0 votes
1 answer

Running a cron job at fixed intervals of time

Just use this instead: 0,30 * * * ...READ MORE

answered Jun 20, 2019 in Linux Administration by ajs3033
• 7,280 points
85 views
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,240 points
156 views