Script works fine in terminal, but not from launch

My Python script works fine in the terminal, but when I try to configure it to run once a day at a specific time using the launch (using software called Lingon), I just cannot run it, From everything I read, it is better to call a Python script from a shell script (I'm on a Macbook by running Yosemite). So this is what I am trying to do. The errors that occur when running the script are as follows:

Invalid TERM environment variable.

env: python3: No such file or directory

At this point, I am sure that this is an environmental problem, but no matter what I try, I just can not get it to work. By the way, I can get the shell script to run as scheduled:

#!/bin/bash echo "hello world." 

The problem occurs when I try to run this:

 #!/bin/bash /Users/jeff/Documents/scripts/my_script.py 

In addition, despite the fact that I have been working with computers for a long time, I still do not quite understand many things, so please tell me how to fix this, for example, I'm a beginner.

0
source share
2 answers

I tried everything that was mentioned, a special thanks to Padraic, but nothing works. It’s strange, because the script works fine when launched from the terminal, but when launched from startup, an error is triggered. I was able to get rid of errors when starting from start, but then the script did not start from the terminal. Very strange. But here, as I did, it started both in the terminal and on a schedule from launch. First, I changed the shebang line:

 #!/usr/bin/env python3 

:

 #!/usr/bin/env /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 

Then I had to indicate in the rest of the script the full path to the files, for example, from this:

 log = open('log_directory/my_log.log', 'a') 

:

 log = open('/Users/jeff/documents/my_script_documents/python/development/log_directory/my_log.log', 'a') 

In any case, it all works now, but I believe that the problem I am facing may have something to do with upgrading my Mac to Yosemite. Some references to a possible error in Yosemite regarding launchd / launchd.conf / launchctl. Well, I would like to believe that these were not my last 4 days, trying to get this to work ... but who knows?

0
source

Based on the article here, you need to create a .plist to run, for example, the following:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <!-- The label should be the same as the filename without the extension --> <string>org.yourusername.my_script-test</string> <!-- Specify how to run your program here --> <key>ProgramArguments</key> <array> <string>/usr/local/bin/python3</string> <string>/Users/jeff/Documents/scripts/my_script.py</string> </array> <!-- Run every hour --> <key>StartInterval</key> <integer>3600</integer><!-- seconds --> </dict> </plist> 

Then:

 $ launchctl load ~/Library/org.yourusername.my_script-test.plist $ launchctl start org.yourusername.my_script-test 

This article describes environment variables.

+1
source

Source: https://habr.com/ru/post/1346998/


All Articles