I wrote a python program that checks a website for new posts, saves a log to a text file and sends me a text message if there is one. I am trying to run this every 5 minutes in a crontab. I am running it in a python environment. The cron file I used:
{*/5 * * * * /Users/my/opt/anaconda3/envs/webscrape/bin/python /Users/my/Desktop/Programming/preply_scrape.py > /dev/null 2>&1}
When I try and save this file in the cron editor I get this dialog box:
"“Terminal” would like to administer your computer. Administration can include modifying passwords, networking, and system settings"
and this error:
""/tmp/crontab.FATUtXZE46":0: bad minute
crontab: errors in crontab file, can't install"
I've been messing with crontab for a few day and even tried launchd but can't figure it out. Could this have something to do with file permissions? Any help with this issue would be greatly appreciated.
I was able to figure it my issue. The issue was that I had to give full disk access to the folder my python programmed was stored and cron. On Mac go to system preference -> Security & Privacy -> Full disk access (on the left side panel). Click on the lock and enter your password to make changes. Click on the plus sign, browse to application -> utilities and find cron. Do the same for your file path.
Related
I'm trying to write basic program with Python. I'm typing Windows commands with os library. Because of that, it doesn't work and wants to be admin. There was being superuser with a command in Linux(sudo). I couldn't find any way to run my program as administrator. I tried wmic and got an error named "Alias not found". Are there any way to run program as administrator?
If you are trying to make a program run in admin mode(the short handle we use for windows). If the object is an executable file or type of script and a few other file types I am not 100% certain of the extensive list. You would just right-click the file and select run as admin mode. If you are trying to run your program in admin mode I do believe that if you make python run as admin mode all the time your .py files should inherit the administrative privileges I would need someone to clarify that though. I am slightly confused as to your question though, as you say typing commands in os library are referring to the CMD(Command Prompt)?
Edit: In case you were referring to CMD open the start menu and type CMD and Right click and open as admin mode.
So, on a Raspberry Pi I'm using a camera app with a web interface, I wanted to add LED lighting by adding a neopixel. I have successfully done this and can now turn it on and off running two python scripts.
Explanation and question:
I have a python script in /usr/local/bin that is executable.
It is owned by 'root root'.
I have a shell script in /var/www/html/macros that is executable and has to run the python script in /usr/local/bin.
The shell script is owned by 'www-data'
When I manually run the python file, it executes the script.
When I manually run the shell script, it executes the python script.
When I run the shell script by clicking on a button on my webpage, it seems to execute the shell script correctly, however, it looks like it doesn't execute the python script.
What can I do to fix this?
I'm not that experienced with permissions, but I wanted to emphasize on the fact that this is a closed system that does not contain any sensitive information. So safety/best practice is not a concern. I just want to make this work.
I'm not an expert in this area, but I believe to access /usr/local/bin/ you need root privileges which explains why you're having success but not Apache.
Rather than give Apache root permissions, it's best to simply remove the requirement from the individual file you want to execute. This can be accomplished by
$ cd /usr/local/bin
$ sudo chmod 777 your_script.py
Now, after 11 hours and a group of people thinking along we found a solution to the problem.
The problem turned out to be that the Web interface can only execute as 'www-data', and the NeoPixel library that the python script depends on needs to be executed as sudo/root.
These two factors make it so that there will never be a direct way of getting the scripts to work together.
However, the idea emerged to use some sort of pipe.
A brilliant user suggested to me to use sshpass. This would allow to pass data to ssh and have it essentially be executed as a root user.
The data from the web interface would be relayed to the sshpass and this would successfully run the needed scripts with the needed privileges.
Special thanks to Minty Trebor and Falcounet from the RRF for LPC/STM Discord!
I've setup Geany a long time ago to compile my Python program on my Windows machine which it then sends to my Pi via scp. It still works fine - but if I take the same file and rename it, it refuses to do it.
I get "scp: /home/pi/scripts/APC2.py: Permission denied" from the Compiler in the MEssage window
And really don't want all my programs called the same thing.
I basically can't remember how I did the setup and can't find it anywhere on the internet.
Any help will be greatly appreciated
I found the link again:
http://www.python-exemplary.com/index_en.php?inhalt_links=navigation_en.inc.php&inhalt_mitte=raspi/en/installation.inc.php
Also my permissions for the new file were incorrect as Geany sends the file to /home/pi/scripts and I log in as root and not the pi user.
I have a Python script that should open my Linux terminal, browser, file manager and text editor on system startup. I decided crontab is a suitable way to automatically run the script. Unfortunately, it doesn't went well, nothing happened when I reboot my laptop. So, I captured the output of the script to a file in order to get some clues. It seems my script is only partially executed. I use Debian 8 (Jessie), and here's my Python script:
#!/usr/bin/env python3
import subprocess
import webbrowser
def action():
subprocess.call('gnome-terminal')
subprocess.call('subl')
subprocess.call(('xdg-open', '/home/fin/Documents/Learning'))
webbrowser.open('https://reddit.com/r/python')
if __name__ == '__main__':
action()
here's the entry in my crontab file:
#reboot python3 /home/fin/Labs/my-cheatcodes/src/dsktp_startup_script/dsktp_startup_script.py > capture_report.txt
Here's the content of capture_report.txt file (I trim several lines, since its too long, it only prints my folder structures. seems like it came from 'xdg-open' line on Python script):
Directory list of /home/fin/Documents/Learning/
Type Format Sort
[Tree ] [Standard] [By Name] [Update]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
/
... the rest of my dir stuctures goes here
I have no other clue what's possible going wrong here. I really appreciate your advice guys. thanks.
No, cron is not suitable for this. The cron daemon has no connection to your user's desktop session, which will not be running at system startup, anyway.
My recommendation would be to hook into your desktop environment's login scripts, which are responsible for starting various desktop services for you when you log in, anyway, and easily extended with your own scripts.
I'd do as tripleee suggested, but your job might be failing because it requires an X session, since you're trying to open a browser. You should put export DISPLAY=:0; after the schedule in your cronjob, as in
#reboot export DISPLAY=:0; python3 /home/fin/Labs/my-cheatcodes/src/dsktp_startup_script/dsktp_startup_script.py > capture_report.txt
If this doesn't work, you could try replacing :0 with the output of echo $DISPLAY in a graphical terminal.
I'm writing a Python application that is executable. It reads and writes to a file. The application uses wx for a GUI and has been given the following permissions:
chmod +x app.py
When I load the application from the terminal like so:
./app.py
The application loads and causes no errors.
However, when I double click the app.py file and click 'execute', everything works perfectly except for the reading and writing of this file. This is a major part of the program and causes errors.
I cannot, for the life of me, understand why this is not working.
I have attempted to set it so that it loads as the root user each time with no luck. I have also been developing as the root user the entire time, so I shouldn't see any issues.
I am using the default Raspbian OS.
It sounds like you need to modify the permissions of the file to be readable/writable/executable by the user you log into the GUI with. Do some reading on Linux File Permissions and see where that takes you.