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.

  • Is this in in roots crontab or in your users crontab? – Panki Aug 30 '19 at 8:27
  • 1
    Is the crontab owner getting any emails containing errors from the cron daemon? – Kusalananda Aug 30 '19 at 8:30
  • Please include the output of grep -i cron /var/log/syslog – Panki Aug 30 '19 at 8: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? and Why does redirection in crontab result in a zero byte file? for example. – Kusalananda Aug 30 '19 at 12:21
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.