Saturday 14 March 2020

crontab doesn't run script

If crontab doesn't run a script and if the output is redirected to a zero length file, it may be because it is missing the #!/bin/bash or #!/bin/sh directive.

Another reason may be that the path is required.
change dotnet to /opt/dotnet/dotnet

Remember that crontab runs under a reduced environment. It may not have the necessary environment variables. For example echo @DOTNET_ROOT is empty when running as crontab. If you run it as su it returns /opt/dotnet

Consider the user you are running the crontab under. Does it need to be su?

In the end another approach was required: execute bash to run the script. This is the full crontab:
# Added dotnet to the path
# It is necessary to execute bash in order to access the environment variables required for dotnet
* */12 * * * bash -l -c '/home/pi/SmartHome/easy-weatherstation/scripts/' > /home/pi/SmartHome/easy-weatherstation/scripts/logs/publishreadings.log 2>&1
*/30 * * * * bash -l -c '/home/pi/SmartHome/easy-weatherstation/scripts/' > /home/pi/SmartHome/easy-weatherstation/scripts/logs/onereading.log 2>&1

Sunday 1 March 2020

the required library could not be found

Problem: Running .net core 3.1 app on a Raspberry Pi returns
"the required library could not be found."

dotnet --version

if the second line is empty then the environment variable needs to be set at startup.

Add a file to /etc/profile.d
sudo nano /etc/profile.d/

export DOTNET_ROOT="/opt/dotnet"

save and reboot

If you want it to run for su too, especially if running a su crontab,
edit /etc/bash.bashrc and add it there too.