-1

I have cronjobs like so

* * * * * /usr/bin/psql -U usename dbname -c "select usename, now(), pg_terminate_backend(pid) from pg_stat_activity where state like 'idle%' and (now() - query_start) > interval '2 hour';" &> /home/fedora/terminate_backend.log
* * * * * /usr/bin/psql -U usename dbname -c "vacuum analyze;" &> /home/fedora/vacuum.log

The second is running and producing the requested, albeit useless, log. The above does not create a log and I have reason to believe that it is not running.

I've tried adding /usr/bin/echo "DUMB" > /home/fedora/dumb.log; in front and still nothing appears.

It looks like so

* * * * * /usr/bin/echo "DUMB" > /home/fedora/dumb.log; /usr/bin/psql -U usename dbname -c "select usename, now(), pg_terminate_backend(pid) from pg_stat_activity where state like 'idle%' and (now() - query_start) > interval '2 hour';" &> /home/fedora/terminate_backend.log

Any help is appreciated. Might it have something to do with env vars? If looked in env and tried adding the host 127.0.0.1, Nothing. And btw, the vacuum one works, so...

artdv
  • 101
  • 1
  • Please work your way through the linked duplicate it will almost certainly help you solve your problem. If it does not it will help you gather information that will help us help you. You should edit that information into your question. – user9517 Mar 08 '16 at 21:57

1 Answers1

0

The answer is in Why is my crontab not working, and how can I troubleshoot it?, but to cut to the chase, it's the %. From man 5 crontab:

   The entire command portion of the line, up to a newline or a  "%"
   character, will be executed by /bin/sh or by the shell specified in the
   SHELL variable of the cronfile.  A "%" character in the command, unless
   escaped  with a backslash (\), will be changed into newline characters,
   and all data after the first % will be sent to the command as  standard
   input.

The crontab entry that has a % is being truncated (and the rest becomes stdin), so the command is failing and the redirect is lost.

mattdm
  • 6,550
  • 1
  • 25
  • 48
  • 1
    You know how SE works why did you not use your close duplicate vote ? – user9517 Mar 09 '16 at 06:32
  • @Iain Because I don't think "this is covered somewhere in a gigantic canonical answer so good luck with that" is very helpful. – mattdm Mar 09 '16 at 09:02