Python Need linux/python help with writing to csv file in cron

  • Thread starter Thread starter devadmin
  • Start date Start date
  • Tags Tags
    Csv File Writing
AI Thread Summary
The discussion centers around troubleshooting a script that successfully writes to a CSV file when executed from the console but fails to do so when run via cron. Key points include the importance of checking system logs like dmesg and syslog for errors, and the suggestion to add a logger entry to confirm if the script is running. A common issue identified is the use of relative paths, which can cause scripts to fail in cron due to its strict security settings. The conversation shifts to the use of Python, with participants expressing their growing appreciation for the language due to its versatility in data science and ease of use, particularly in comparison to other programming languages. The community highlights the benefits of Python's extensive libraries and supportive community, making it a preferred choice for various projects.
devadmin
Admin
Messages
140
Reaction score
1
I'm writing a simple script that writes to a csv file. When ran from console it works fine. When ran with cron, it doesn't write. No errors in the log. All files and folders are 777. The cron is active and running. What am I missing?
 
Technology news on Phys.org
What do:
Code:
$ dmesg
$ cat /var/log/syslog
say?
If there was an error, it should show up in one of those.

How do you know that the script is actually running?

I recommend to start the script with something like
Code:
#!/bin/bash
logger "Running simple script that writes to csv file"
so that there will always be an entry in the syslog. Note that standard output does not go anywhere.
If after that, there is still no entry in the log (after waiting for the script to trigger), that implies that the script did not actually run.
 
oh derp, I had a relative path to the file :D
 
I have found cron to be extremely picky about security settings, and not very helpful at steering you to set them correctly.
 
Seems like a good place to ask this, how many of you use Python at work or for personal projects? 3 years ago I had never once touched it now it’s my go to language. Still not my best but the dominance it has in data science plus the huge variety of tasks it can do are very appealing.
 
Jameson said:
Seems like a good place to ask this, how many of you use Python at work or for personal projects? 3 years ago I had never once touched it now it’s my go to language. Still not my best but the dominance it has in data science plus the huge variety of tasks it can do are very appealing.
Agreed, I'm just a few months in and I love it. It's so clean. Looking at nested indents can take getting used to. There are also so many libraries, great community.
 
The nested part was weird for me at first but with a good editor like Sublime the coloring and formatting help make it very obvious what code goes to what chunk.
 
I'm still slightly better at LabVIEW (and was therefore extremely excited when NI put out the Community Edition), but I like many things about Python. As text-based languages go, it's my favorite, because it appears optimized for developer time.

I do all my projects using various databases (either relational with SQL, or now I'm starting to use Neo4J with Cypher) and Python. That's it.
 
Back
Top