How to continuously run script on EPIC through SSH?

How can I continuously run the script on EPIC like it is a strategy in PAC control?

I have tried putting the code with a continuous loop so EPIC can always check the button state and response as programmed.

  • when the shell window is opened, the script is running continuously.
  • when I close the shell window on my laptop, the script on EPIC stops too.

my setup

  • EPIC with SSH access
  • Python script in the secured area of EPIC
  • SSH access from bash terminal on VS code

my code

#ledControl.py
import optommp
grvEpic = optommp.O22MMP()

while True:
    #check pushbutton on module 0 channel 1
    if grvEpic.GetDigitalPointState(0, 1) == 1:
        grvEpic.SetDigitalPointState(1, 0, 1) #turn on pushbutton LED
    else :
        grvEpic.SetDigitalPointState(1, 0, 0) #turn off pushbutton LED

grvEpic.close()

Thanks

I can think of two ways to go about this, one way is to use nohup to ignore the HUP (hangup) signal that kills the script when you close the shell window along with “&” to run the script in the background, so the full command would be: nohup python ledControl.py &
Another option is to execute the script from Node-RED. Just use an exec node to run the command python ledControl.py & and you’re good to go. Either method will keep it running without needing an ongoing SSH session.

Also, while testing this I noticed the script takes up a lot of CPU, so I strongly recommend that you add a loop delay. The while True: is going to run the get/set code as fast as it possibly can, which takes up a lot of processing power, but by delaying for even a fraction of a second you can free up a lot of CPU cycles and reduce the impact that this script will have. Just import time and then have time.sleep(0.1) in the loop to delay for a tenth of a second and it’ll be much more efficient.

Thanks for posting to the forum! Let us know if you have any other questions.

1 Like

When I need to run a long running script in shell I use the tmux utility. It is installed on EPIC.

http://man7.org/linux/man-pages/man1/tmux.1.html

Edit: This looks like something you want running all the time though, I would look in setting it to run with an init.d script.

1 Like