Scheduled Task Raspberry Pi

bede123
bede123 used Ask the Experts™
on
Hello Internet!

I have a few usb miners running on a raspberry pi.

this is what i'd like to achieve.

  1. automatically reboot pi every... say... 4 hours
[list=2]when pi starts up - start screen session and run cmd: sudo /home/pi/git/vthoang/cgminer/cgminer -o stratum+tcp://eu.stratum.slushpool.com:3333 -u zbw123.worker1 -p x --gekko-2pac-freq 150 [/list]

there are a few examples of this being done that i can find online but they all seem to assume a certain level of linux understanding and the truth is i know absolutely nothing about linux. i can follow instructions to the letter but thats about it! :-)

i have bought a book "for dummies" but i'm not finding the answers i need. If it were windows i'd wright a start.bat file i guess.

I downloaded a GUI for crontab which helps you manage scheduled tasks but of course it requires the appropriate files to exist already so that i may run....
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Engineer
Distinguished Expert 2018
Commented:
A   .BAT file is called a script on linux/unix.
A script can be written in a variety of languages perl, python, .. etc. for your purpose then command shell is easiest.. a bash script.
So put your command line in such a script:

miner.sh
#!/bin/bash

sudo /home/pi/git/vthoang/cgminer/cgminer -o stratum+tcp://eu.stratum.slushpool.com:3333 -u zbw123.worker1 -p x --gekko-2pac-freq 150

Open in new window


Now if you want to start this regularly use cron...
install cron  and use crontab to add an entry...
Not sure why you need the reboot etc.  In Unix most command don't need to have the screen active... most stuff can be done through remote logon through ssh (putty from Windows)

Author

Commented:
hi noci, thanks for the quick reply.

where should be the best place to store miner.sh file?

also with regard to the reboot... what seems to happen is every so often one of the usb miners will switch off/freeze and if left unnoticed this causes pi to freeze meaning i can no longer VNC into it. thats why i though if i simply force a reboot every so often it will keep everything alive and fresh
nociSoftware Engineer
Distinguished Expert 2018

Commented:
can be anywhere is you can still find it...
/usr/local/bin   would be a good place if you want to call it as a command. (in that case you may drop the .sh extension and name it just miner).

Also then make the file executable
 chmod +x miner.sh

Open in new window

 if you want to call it directly in stead of bash miner.sh..

Be aware that in cron you may need to prefix all commands with the right path....  (/usr/local/bin/..  f.e.).
But what would cause the freeze...., if the pi has issues with power f.e. (too much current drawn) then brownout may cause it to halt...
in that case a scheduled reboot would fail as well.
Be sure you have enough power for USB devices. 1A PSU might not be sufficient. possibly feed the USB devices through a powered HUB.

VNC is a rather huge program...,  try putty /ssh instead. You will get a command line but with a lot less effort.
(VNC will also cause the GPU to draw extra power...).

Author

Commented:
yes i'm def using a powered hub.

this is what i have so far:

i called in runMiner.sh and saved it to /home/pi/git/vthoang/cgminer

#!/bin/bash

sudo /home/pi/git/vthoang/cgminer/cgminer -o stratum+tcp://eu.stratum.slushpool.com:3333 -u zbw123.worker1 -p x --gekko-2pac-freq 200

Open in new window


then i adjusted this:

nano ~/.config/lxsession/LXDE-pi/autostart

Added this line to the end of the file:

@lxterminal

so that the terminal automatically opens up  on reboot.

but the cron job doesn't appear to start. the terminal opens up but thats it....
nociSoftware Engineer
Distinguished Expert 2018
Commented:
The problem is this commands isn't a graphical command.
lxterminal won't know what to do....
You could help lxterminal by telling it what you want:
for cron you need another tool the cron daemon.., and that runs in the background, it wiil (& should) never show up on the foreground..
(and runs timed jobs in the background)...
The LXDE autostart will run when LXDE starts...
replace your command with
@lxterminal -e /the/path/to/miner.sh

to execute the lxterminal program and have THAT execute your miner.

btw. You could check with
ps | grep miner 

Open in new window

if your miner is running from any terminal.

Author

Commented:
thanks for the reply. was just about to type out my progress so far an then you posted this message.

i have just got it to work by doing the following:

show hidden files
open .bashrc
locate the very bottom and paste:

~/git/vthoang/cgminer/runMiner.sh

right click on runMiner.sh and allow anybody to run the file under permissions.

and hey presto it works.

ref: http://blog.startingelectronics.com/auto-start-a-desktop-application-on-the-rapberry-pi/

I will also try pasting the cmd after @lxterminal to confirm that as well.

now all i need to do is to have the rasp pi automatically reboot every so often and we're away!

Author

Commented:
yep:

@lxterminal -e path/to/script.sh
nociSoftware Engineer
Distinguished Expert 2018

Commented:
.bashrc will start the miner on ANY shell access, not just when you want it... (f.e. when you login with putty/ssh).

Author

Commented:
Yes I discovered that so I have changed it to what you suggested.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial