-1

I'm trying to start a script containing cgminer for mining when the raspberry pi reboots however it doesn't.

My crontab contains the following.

@reboot sleep 120 && sudo /home/pi/StartVPN.sh
@reboot sleep 120 && /home/pi/Run_Miner_SHA256.sh
0 6 * * * sudo shutdown -r

@reboot sleep 120 && sudo /home/pi/StartVPN.sh => Runs perfectly after 2 minutes my VPN is connected with the server.

@reboot sleep 120 && /home/pi/Run_Miner_SHA256.sh => Never runs and I must run it manually.

0 6 * * * sudo shutdown -r => Works fine and the raspberry pi reboots at 6 AM.

My "Run_Miner_SHA256.sh" file contains the following:

cd /home/pi/mining/newpac/cgminer && sudo nohup ./cgminer -o stratum+tcp://192.168.100.100:3256 -u 75ZNRZpEqYBM72GwGi6LCjaKM5Ao715ijD -p anything --gekko-newpac-freq 40  >/dev/null 2>&1 &

What I'm missing here?

3 Answers 3

0

add the following line above your line

TERM=xterm
1
  • thank you very much, this did the job. Excellent
    – Zack Tim
    Commented Sep 9, 2021 at 12:45
1

for debugging purposes remove the >/dev/null 2>&1 & and redirect it to a log file

BTW why do you need the nohup and the & at the end ?

3
  • I'm using the nohup to create a process in the background
    – Zack Tim
    Commented Sep 8, 2021 at 22:12
  • I did what you suggested and the log has this line: Error opening terminal: unknown.
    – Zack Tim
    Commented Sep 8, 2021 at 22:29
  • nohup doesn't create a process in the background; & at the end does. nohup redirects the standard IO streams (in, out, error) to make the process less prone to fatal "hang-up"s -- eg., while it is running in the background (see man nohup).
    – goldilocks
    Commented Sep 9, 2021 at 19:03
1

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.

4
  • I actually tried with sudo and non sudo, it doesn't run the script. Here is the mycronlog output : HOME=/home/pi LOGNAME=pi PATH=/usr/bin:/bin LANG=en_GB.UTF-8 SHELL=/bin/sh PWD=/home/pi
    – Zack Tim
    Commented Sep 8, 2021 at 22:09
  • $printenv => pastebin.pl/view/7d1a5ce4
    – Zack Tim
    Commented Sep 8, 2021 at 22:19
  • 1st coment: Sorry - I do not understand... you tried... what did you try? Your mycronlog output looks correct. 2nd comment: The output at pastebin also looks correct. Note in particular the PATH environment variable. This was only to show how different your cron environment is from your interactive shell (the command line). Please see the revised answer.
    – Seamus
    Commented Sep 9, 2021 at 9:05
  • I'm sorry I should have been more specific, I meant that I used : #sudo crontab -e and #crontab -e . I tried @Oren solution by adding TERM=xterm and it worked now.
    – Zack Tim
    Commented Sep 9, 2021 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.