1

I need to restart one of my services regularly, I tried to to put this into my crontab:

0 0 * * * systemctl --user restart bot 

I found that it doesn't work, after a few days when I check the status of the service, the uptime of it is over 2 days. If I run the same command manually it works, i use the root user BTW, it's VPS with nothing important on it.
Why wouldn't this work? what could be the issue here?
If I check /var/log/syslog this is the only line that's related to this particular job:

Aug 30 08:09:01 ubuntu CRON[21197]: (root) CMD (systemctl --user restart bot &>/var/log/bot.log)  

I edited the schedule a dozen times to let it run the next minute to see if it works. Lines above and below this are about other jobs which work without any problems.

SparedWhisle
  • 3,588
  • 4
  • 22
  • 35
  • Is this in in roots crontab or in your users crontab? – Panki Aug 30 '19 at 08:27
  • 1
    Is the crontab owner getting any emails containing errors from the cron daemon? – Kusalananda Aug 30 '19 at 08:30
  • Please include the output of `grep -i cron /var/log/syslog` – Panki Aug 30 '19 at 08:30
  • Your actual command scheduled (as seen in the log output) seems to be different from the one you mention in your question. The `&>` in that command would not work, as described in a few other questions regarding this: [How to redirect output to a file from within cron?](//unix.stackexchange.com/q/52330) and [Why does redirection in crontab result in a zero byte file?](//unix.stackexchange.com/q/121037) for example. – Kusalananda Aug 30 '19 at 12:21
  • I did some changes after the initial setup. Basically just the time and the `&>` redirection. Just now I tried something else, I put the commond in a file, then put the `/path/to/myfile.sh` into crontab. Now I'm getting mail that says `Failed to connect to bus: No such file or directory` – SparedWhisle Aug 30 '19 at 12:30
  • found this question: https://unix.stackexchange.com/questions/495060/systemctl-doesnt-work-from-crontab which was not answered. – SparedWhisle Aug 30 '19 at 12:35
  • 1
    Could you please update your question so that it is consistent with what you currently have, and include that last piece of information about `Failed to connect to bus`. Someone reading this should not need to read all the comments to figure out what you have tried and what state this is at currently. – Kusalananda Aug 30 '19 at 13:38

0 Answers0