shartshooter
shartshooter

Reputation: 1811

Crontab and Python | Won't write CSV

I've got a very simple python program that generates a csv. From the command line when I execute

python test.py

I have no issues. A CSV is generated. However, when I runs through a crontab I get notification that it ran successfully but there is no CSV.

Not sure what I need to change

test.py

def writeCSV():
    import csv
    print 'Cron Started'

    with open('testout.csv', 'wb') as csvoutput:
        writer = csv.writer(csvoutput)
        writer.writerow('test')

    print 'Cron Complete'


writeCSV()

Crontab -l

*/1 * * * * python /Users/Me/Desktop/test.py

Upvotes: 2

Views: 1813

Answers (1)

falsetru
falsetru

Reputation: 369424

If you don't specify the path as an absolute path, the file will be generated in the home directory.

Check your home directory.

Or if you want to generate the file in the specific directory, specify the path as absolute path, or use cd command before execute the python command.

Upvotes: 6

Related Questions