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,660 points
691 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,130 points

Related Questions In Linux Administration

0 votes
1 answer
0 votes
0 answers

Linux Command for getting a dump of hex values bytes from Pcap File

I require a Linux command to display ...READ MORE

Apr 13, 2022 in Linux Administration by Rahul
• 9,680 points
976 views
0 votes
0 answers

Linux Command for getting a dump of hex values bytes from Pcap File

I require a linux command to display ...READ MORE

Apr 20, 2022 in Linux Administration by Edureka
• 13,690 points
638 views
–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,220 points
3,482 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 5, 2019 in Linux Administration by Omkar
• 69,220 points
2,923 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,890 points
1,359 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 21, 2019 in Linux Administration by ajs3033
• 7,300 points
948 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
1,210 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP