Home > OS >  Restart Opencanary from Crontab
Restart Opencanary from Crontab

Time:10-06

I have a programm called opencanary running at a virtual environment at my Raspberry Pi with Ubuntu 18.04 installed. I want to restart it every 30 Minutes using crontab. For testing I set the script to run every 3 Minutes as you can see below. When I execute the script manually it's working fine. When using crontab to run it it doesn't and I can't find out why it fails.

This is what my script looks like:

#!/bin/bash
SHELL=/bin/sh
. /home/pi/.bashrc
source /home/pi/canary-env/bin/activate && cd opencanary && opencanaryd --restart

After creating the script I added it to crontab -e:

*/3 * * * * /home/pi/restartOC.sh>>test.log

When I look at the cron.log file I can see that the script is executed:

Sep 29 08:33:01 DiskStation CRON[20880]: (pi) CMD (cd /home/pi && sh restartOC.sh>>test.log)

the test.log file stays empty.

Does someone know what I am doing wrong?

Edit 05.10.2021 At the github of opencanary I was told that I don't have to use the 'cd opencanary'. I followed the advice and edited my script:

#!/bin/bash
SHELL=/bin/sh
. /home/pi/.bashrc
source /home/pi/canary-env/bin/activate && opencanaryd --restart

The script is still working when executed manual but The Problem does still exist when running the script from cron.

CodePudding user response:

I solved the problem by calling 'which opencanaryd' at the terminal this will return the path where the opencanaryd command is located.

In my case it is /usr/local/bin/opencanaryd

With this knowledge it is possible to edit the script so cron can find the command:

#!/bin/bash
SHELL=/bin/sh
. /home/pi/.bashrc
cd /usr/local/bin/ && . opencanaryd --restart
  • Related