0

I'm struggling to auto start .sh files on a Pi4 and need some help please. I want to start more than one .sh file at every reboot for power losses etc and also every 12hrs whilst unning. I go into crontab -e and enter:

0 */12 * * * /home/pi/git/vthoang/cgminer/x1R606b.sh

...but nothing happens. I'm aware of the rc.local folder for reboot coding but that doesn't work either. Can someone help a novice with step coding instructions please? I'm running a small USB farm and want to refresh cgminer to contain the zombies :)

Regards all

1

Assuming that your scripts all execute properly when run manually from the command line, this should get things moving forward:

You will need two separate crontab entries for what you want to do.

  1. To start at reboot, try this:
@reboot ( /bin/sleep 30; /bin/bash /home/pi/git/vthoang/cgminer/x1R606b.sh >> /home/pi/cronjoblog 2>&1)
  1. To start a script at 12 hour intervals
0 01/12 * * *  /bin/bash /home/pi/git/vthoang/cgminer/x1R606b.sh >> /home/pi/cronjoblog 2>&1  

A few comments:

  • The sleep command may be useful for jobs executed @reboot. It will give your system's services time to get started before attempting to execute your script. If your script doesn't depend on system services to execute successfully, it probably won't hurt to use sleep.

  • The /bin/bash assumes your script is running under bash, and it may or may not be necessary. If you have a proper shebang in your shell script (e.g. #!/bin/bash as the first line), it won't be needed.

  • You may benefit from redirecting any stderr output from your script to a file so that you won't miss any error messages that may be generated by your script.

  • You mentioned starting more than one job at reboot. In the interest of simplicity, consider a separate @reboot line for each job you want to start.

  • Refer to the crontab guru to help with the syntax for scheduling your jobs.

You may want to read some other Q&A here(1, 2, 3, 4) regarding the use of cron to schedule jobs. And this recipe covers some details on the environment under which cron runs.

| improve this answer | |
0

That would be:

@reboot /home/pi/git/vthoang/cgminer/x1R606b.sh
0 0,12 * * * /home/pi/git/vthoang/cgminer/x1R606b.sh

Note that there are some issues with running @reboot if you are not root, so you probably want to do this as root.

If you want to test if it works, you can just try to put

@reboot /bin/date > /tmp/rebootproof

in root's crontab and reboot.

| improve this answer | |
  • Hi and thanks for your response. I followed your instructions but it hasn't worked. In the terminal, I entered sudo crontab -e and at the first available empty line entered the info. Is there anything else I can try, maybe running code from the terminal to restart my path manually at each boot? This really is the only thing left between me and this build over the last few months ;) – Cohenpol Dec 4 '19 at 20:25
  • There was a mistake in my last test; date is in /bin on a Pi. You should see the /tmp/rebootproof however, but it would be empty. Try the @reboot /bin/date > /tmp/rebootproof and you will see that that works. – Ljm Dullaart Dec 4 '19 at 21:33
  • 1
    If the @reboot-test works, then you know the problem is not with cron. Then the next step would be why your script does not work. Try shellcheck.net to see if there are any issues with your script. – Ljm Dullaart Dec 4 '19 at 21:36

Your Answer

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

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