The following should work, but I am not sure about the command, since I am not familiar with gminer.
The script
Paste the text below in an empty file, save it as check_gminer.py, save it somewhere:
#!/usr/bin/python3
import subprocess
import getpass
curruser = getpass.getuser()
service = "gminer"
def createlist_runningprocs():
processesb = subprocess.Popen(["ps", "-u", curruser], stdout=subprocess.PIPE)
process_listb = (processesb.communicate()[0].decode("utf-8")).split("\n")
return process_listb
def runsornot():
runningprocs_list = createlist_runningprocs()
if not application[:15] in str(runningprocs_list):
subprocess.Popen(["sh", "m.sh"])
else:
pass
runsornot()
Editing cronfile
Add the following line to your cronfile (type crontab -e
in a terminal):
* * * * * python3 /path/to/script/check_gminer.py
The script looks every minute if the service runs ant restarts it if not. The question is if it works or not if your GPU has problems. We'll have to see.
Alternative procedure, if the above method is not sufficient for your situation
The alternative (reboot) needs administrator privileges. Therefore, if you need to run the reboot command by a cronjob, you need to edit /etc/crontab
(sudo nano /etc/crontab
), In which you can set by which user the command should be run (<> crontab -e
).
Add the line:
0 */3 * * * root reboot
To the /etc/crontab
and your computer will restart every three hours.
http://askubuntu.com/questions/13730/how-can-i-schedule-a-nightly-reboot
– Chinmaya B Jun 14 '14 at 18:00