I'm running Ubuntu 18.04 I'm using Postgres that came with apt.

I wrote a simple bash script to stop the database.

#!/bin/bash -x

/etc/init.d/postgresql stop

When running this script in a cronjob owned by root, it does not stop the database.

When I executed the script manually on the command line, it worked as expected. selinux is not enabled.

I then piped STDOUT to a file

59 11 * * * /etc/init.d/x.sh >> /var/log/pgsql_tmp.log 2>&1

The only output is this.

+ /etc/init.d/postgresql stop
  • Redirect the STDOUT to file and show us what is the result. May 29, 2022 at 12:34

1 Answer 1


I changed the script to use

service postgresql stop

and I was able to to get more STDOUT

+ /usr/sbin/service postgresql stop
/usr/sbin/service: 169: /usr/sbin/service: systemctl: not found
/usr/sbin/service: 182: /usr/sbin/service: sed: not found
/usr/sbin/service: 187: exec: systemctl: not found

For example, to fix,

/usr/sbin/service: 169: /usr/sbin/service: systemctl: not found

I opened /usr/sbin/service with vim on line 169

169    if ! systemctl --quiet is-active multi-user.target

and inserted the whole path

169    if ! /bin/systemctl --quiet is-active multi-user.target

I did it for the others too, now the cron works.

  • Wouldn't it be preferred to update the PATH in you crontab file ? Then you should not have to worry about updated overwriting your changes.
    – user9517
    May 30, 2022 at 15:05
  • 1
    good point @user9517
    – BioRod
    May 30, 2022 at 21:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .