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
26 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
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
• 67,120 points
166 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
• 67,120 points
68 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,810 points
24 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
1,193 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 in Linux Administration by Upasana
• 8,410 points
16 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 in Linux Administration by ajs3033
• 7,240 points
15 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
65 views