0

I am trying to make an script that will every second read string from a file, and execute it.

executer.pyc:

import os, time
f = open("/root/codename/execute","a")
f.write("")
f.close()
cmd=open('/root/codename/execute', 'r').read()
if not cmd=="":
    os.system(cmd)
    os.system("rm /root/codename/execute")
time.sleep(1)
os.system("python executer.pyc")

Problem is, that it constantly f's up whole ps -aux and other similiar commands. How can i make, that it will kill itself and then launch itself again? My idea, is a parent script that will launch executer.pyc everytime that script closes itself. But how can i make it, that it will not have effect like executer.pyc? I know this whole system how it works is kinda bad, but i just need it this way (reading from file "execute"). Please help!

Thanks in advance!

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Riki137
  • 2,076
  • 2
  • 23
  • 26

2 Answers2

0

It will be much easier to let this script run continuously. Look at How to use a timer to run forever? This will show you how you can repeatedly execute the same command.

Community
  • 1
  • 1
unholysampler
  • 17,141
  • 7
  • 47
  • 64
0

instead of

os.system("python executer.pyc")

you can use execfile()

Michał Šrajer
  • 30,364
  • 7
  • 62
  • 85