1

My pc runs a program when it boots. Sometimes the program stops working after a few hours, but it will work fine when it reboots. So, I want to schedule my pc to reboot every 3 hours to prevent the program to be stopped. I'm using Ubuntu 14.04.

edit: The program doesn't stop, it just doesn't work with the maximum power of the pc but I need it to work with full power.

Majidak
  • 47

1 Answers1

5

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.

Jacob Vlijm
  • 85,475