Two things:
First Thing:
WRT your error: You need to remember that cron
jobs do not run under the same environment as your interactive shell. You can see this by running printenv
in a cron
job, and then comparing the output to same command executed from your command line (interactive shell); i.e.
@reboot printenv > /home/pi/mycronlog.txt 2>&1
and then from the command line:
$ printenv
As you'll see, there are substantial differences! Also note that cron
defaults to sh
(not bash
), and that may not work for all the commands in your script.
I won't try to debug your code, but I will make some observations based on a quick look:
it's certain that if you either change your cron
environment, or respect the current environment (e.g. by using full path statements instead of ./
), it will run.
there is no point using nohup
in a cron
job (REF). Read man nohup
./
should be a specific path; e.g. /home/pi
Have you tried something perhaps less convoluted?; e.g. instead of:
@reboot sleep 120 && /home/pi/Run_Miner_SHA256.sh
perhaps try something like this:
@reboot sleep 120; /home/pi/mining/newpac/cgminer -o stratum+tcp://192.168.100.100:3256 -u 75ZNRZpEqYBM72GwGi6LCjaKM5Ao715ijD -p anything --gekko-newpac-freq 40 >/dev/null 2>&1
NOTE: There are several things left unclear from your question; for example, why send all output to /dev/null
?, is cgiminer
a folder name and the name of an executable file? (cgiminer/cgiminer
- or cgiminer
?)
Second Thing:
Using sudo
in your cron
jobs works in RPi OS, but it will fail in most distros, and is not "best practice". If you need elevated privileges in a cron
job, you should run under the root crontab
:
$ sudo crontab -e
When running in the root crontab
, you don't need sudo
at all.