Scheduled Task Raspberry Pi

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....
LVL 1
bede123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
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)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bede123Author 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
0
nociSoftware EngineerCommented:
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...).
0
bede123Author 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....
0
nociSoftware EngineerCommented:
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.
0
bede123Author 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!
0
bede123Author Commented:
yep:

@lxterminal -e path/to/script.sh
0
nociSoftware EngineerCommented:
.bashrc will start the miner on ANY shell access, not just when you want it... (f.e. when you login with putty/ssh).
0
bede123Author Commented:
Yes I discovered that so I have changed it to what you suggested.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.