Wasted the entire day trying to schedule a task in my Penguin terminal. Cron won’t log anything no matter how I set the permissions. I just realized that maybe I need to install the dependencies of the script in my virtual environment but I have a feeling after that it still won’t work because the logs are just blank. I don’t know what the hell I’m doing wrong. Why is scheduling a script more difficult than writing a script? I tried monit and it’s a crap show. Full disclosure I am working with ChatGPT but I wrote my entire script that way and it works when I run it manually. Any help would be much appreciated, it might help if you start by asking questions but here’s my Cron entry:
25 22 * * * /bin/bash -c 'source /home/johnfpederson/newenv/bin/activate && /home/johnfpederson/newenv/bin/python /home/>
Hi John,
Merry Christmas and welcome to the Forum (!)
A little bit of background first; I use AI a fair bit (not currently ChatGPT, although I have) partly in an attempt to know what I’m talking about when I comment on “AI” and partly because it can sometimes point me in the right direction. That aside, 95% of the “code” or instructions it generates in response to queries I give it is either wrong in the sense that it literally doesn’t work, or wrong in that it’s the wrong or a bad approach to solving any particular issue. So, if you write something that works then ask “AI” to enhance it in some way, be surprised if it “DOES” work …
Looking at your particular CRON entry, without going into what it does there appear (?) to be two errors … firstly you have an un-terminated or unbalanced quote, i.e. an apostrophe before the “source” with no close. You then also appear to have a redirect (greater than) outside of quotes at the end of the line, which may attempt to redirect the output of the command to … well, as you’ve not put anything, I’m not entirely sure what it will do, I’m guessing generate an internal error.
Moving on, I think when you use “source” from within a CRON file, you get problems if you’re not using the default shell. Try setting the SHELL environment variable and doing something like;
SHELL=/bin/bash
25 22 * * * source /home/johnfpederson/newenv/bin/activate && /home/johnfpederson/newenv/bin/python /home/ > /tmp/debug.log 2>&1
Alternatively, you could just call the version of Python from within your virtual environment directly (which should implicitly set your venv) so something like;
25 22 * * * /home/johnfpederson/newenv/bin/python (your script) > /tmp/debug.log 2>&1
Then see what appears in /tmp/debug.log …