-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 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,740