- #1
- 140
- 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?
$ dmesg
$ cat /var/log/syslog
#!/bin/bash
logger "Running simple script that writes to csv file"
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.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.
To write to a CSV file in a cron job, you can use the Python csv
module. First, import the module and open the CSV file using the csv.writer
function. Then, use the writerow()
method to add data to the CSV file. Finally, close the file when finished.
The csv.writer
function has several optional parameters that allow you to specify the delimiter, quote character, and other formatting options for the CSV file. You can refer to the Python documentation for more details on how to use these parameters.
Yes, you can use the crontab
command to schedule the job to run at a specific time. The syntax for scheduling a cron job is minute hour day_of_month month day_of_week command
. You can refer to the cron documentation for more information on how to set up a cron job.
If your cron job is not working, there are a few steps you can take to troubleshoot the issue. First, check the job's output for any errors. You can also check the cron log file for any error messages. Additionally, make sure the correct path to the Python interpreter is specified in the cron job command.
Yes, you can write to multiple CSV files in a single cron job by repeating the steps for each file. Alternatively, you can use a loop to iterate through a list of CSV files and write data to each one. Just make sure to close each file after writing to it to avoid any data loss.