Score:0

cronjob does not stop postgres

es flag

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
Romeo Ninov avatar
in flag
Redirect the STDOUT to file and show us what is the result.
Score:-1
es flag

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.

user9517 avatar
cn flag
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.
BioRod avatar
es flag
good point @user9517
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.