I take notes in class on my computer and share these notes via a public folder on dropbox. When I take notes in class, I create a lot of unnecessary files (I take notes in LaTeX) before I generate a PDF. I don't want to clutter my dropbox space with the unnecessary files, and would rather post only the PDFs to dropbox.
In order to facilitate all of this, I set up a cronjob that runs a python script (below) after every class (weekly). Sometimes, I stay back for a few minutes while I fix something in my notes before I export a PDF, so the python script has a bunch of sleep
s in it, waiting for the PDF to be generated. I accidentally manually ran that script today, and need help stopping it.
import os
import subprocess
from sys import exit as crash
from datetime import date as dt
from time import sleep
def getToday():
answer = dt.strftime(dt.today(), "%b") + str(int(dt.strftime(dt.today(), "%d")))
return answer
def zipNotes(date):
today = getToday()
while 1:
if today not in os.listdir('.'):
with open("FuzzyLog", 'a') as logfile:
logfile.write("Sleeping\n")
sleep(60*5) # sleep 5 minutes
continue
if "Notes.pdf" not in os.listdir(today):
with open("FuzzyLog", 'a') as logfile:
logfile.write("pdf not exported. Sleeping\n")
sleep(60*5) # sleep 5 minutes
continue
subprocess.call("""zip Notes.zip */Notes.pdf""", shell=True)
crash(0)
zipNotes(getToday())
Since the script doesn't find any files made today (I could easily just create a dummy file, but that's not a "proper" solution), it loops through the sleep condition infinitely. Since the looping conditions are quite simple, I can't count on the process to be active for very long to "catch it in the act" to get its PID to kill it.
ps aux | grep python
doesn't show me which PID is running the python script I want to kill, nor does ps -ax | grep python
or ps -e | grep python
.
Does anyone have any idea how I can track a python script while it's sleeping?
I'm on Mac OSX 10.7.5 (Lion), if that matters