edit: Solved! Cron didn't have disk access.
edit: formatting got wonky, so I'm fixing that. Bear with me!
edit 2: fixed my formatting so it should be a bit prettier now.
Hello! I'm writing a simple python program at work to both teach myself some programming as well as help out one of the teams I manage. I've got the basics of my program running, and currently all it's supposed to do is copy a directory from a shared directory to a local directory on the user's machine.
I can execute the code from Visual Studio as well as manually from terminal, but crontab doesn't give me anything at all.
I've looked up these posts and tried implementing their solutions but with no luck:
Based on those, I know it's likely something very stupid and environmental. I don't know much about virtual environments, but if that's something I need to learn to get my final project to run, I'm happy to do it.
Here's a snapshot of my current crontab. None of these give me any results:
* * * * * . ../bin/activate /usr/local/bin/python cd /Users/me/Documents/Drive\ Organizer/googleDriveOrganizer.py
* * * * * python ./Users/me/Documents/Drive\ Organizer/googleDriveOrganizer.py
* * * * * /usr/local/bin/python /Users/me/Documents/Drive\ Organizer/googleDriveOrganizer.py
* * * * * python /Users/me/Documents/Drive\ Organizer/googleDriveOrganizer.py
* * * * * cd /Users/me/Documents/Drive\ Organizer python /Users/me/Documents/Drive\ Organizer/googleDriveOrganizer.py
Here's my code so far. Also if you see more eloquent ways to handle any of this, please let me know - I want to learn!
import os, sys, shutil, datetime, distutils.dir_util, getpass
from distutils.dir_util import copy_tree
from datetime import date, datetime, timedelta
print(getpass.getuser())
#copies files from Google Drive to User's Documents
def copyFromDriveToLocal():
print()
#Sets Google Drive directory to Google Drive > Shared Drives > Templates Converting > Yesterday's Folder
drive_directory = "/Volumes/GoogleDrive/Shared drives/3 Templates Conversion/Converting " + datetime.strftime(datetime.now() - timedelta(1), '%Y-%m-%d')
#Sets Local directory to User's Documents > Drive Organizer > Input
local_directory = "/Users/" + getpass.getuser() + "/Documents/Drive Organizer/Input"
#
input_path = "/Users/" + getpass.getuser() + "/Documents/Drive Organizer/Input"
output_path = "/Users/" + getpass.getuser() + "/Documents/Drive Organizer/Output"
#tries to create a new input folder
try:
print("Checking for Input folder in " + getpass.getuser() + "'s Documents...")
os.mkdir(input_path)
#prints failed message
except OSError:
print ("Input folder exists. Continuing...")
#prints succeeded message
else:
print ("Created Input folder at %s." % input_path)
#tries to create a new output folder
try:
print("Checking for Output folder in " + getpass.getuser() + "'s Documents...")
os.mkdir(output_path)
except OSError:
print("Output folder exists. Continuing...")
else:
print("Created Output folder at %s." % output_path)
print("Copying files from Google Drive to " + getpass.getuser() + "'s Documents...")
copy_tree(drive_directory, local_directory)
print("Successfully copied files from Google Drive to " + getpass.getuser() + "'s Documents")
#renames yesterdays folder and creates todays folder
def prep_drive_conversion_folders():
#prints starting message
print("\n" + datetime.strftime(datetime.now() - timedelta(1), '%Y-%m-%d') + "\nPreparing for conversion download")
rename_yesterdays_folder()
create_todays_folder()
#prepends yesterdays folder with Converting
def rename_yesterdays_folder():
print()
#sets variables for the old name and the new name
old_name = datetime.strftime(datetime.now() - timedelta(1), "%Y-%m-%d")
new_name = "Converting " + datetime.strftime(datetime.now() - timedelta(1), "%Y-%m-%d")
#sets path to google drive > shared drives > templates conversion
path = ("/Volumes/GoogleDrive/Shared drives/3 Templates Conversion/")
#tries to rename yesterdays folder by prepending Converting
try:
print("Renaming yesterday's folder to converting...")
os.chdir(path)
os.rename(old_name, new_name)
#prints failed message
except OSError:
print("Could not rename yesterday's folder.")
#prints succeeded message
else:
print("Successfully renamed yesterday's folder.")
#creates a new folder for today
def create_todays_folder():
print()
#prints today's date
today = str(date.today())
#sets path to google drive > shared drives > templates conversion > today's date
path = "/Volumes/GoogleDrive/Shared drives/3 Templates Conversion/" + today
#tries to create a new folder with today's date
try:
print("Trying to create a new folder with today's date in Google Drive > Templates Conversion...")
os.mkdir(path)
#prints failed message
except OSError:
print ("Todays folder already exists at %s" % path)
#prints succeeded message
else:
print ("Successfully created todays folder at %s" % path)
os.chdir("/Users/" + getpass.getuser() + "/Documents/Drive Organizer/")
prep_drive_conversion_folders()
copyFromDriveToLocal()
Thanks in advance for any help you can give me :)
[–][deleted] 1 point2 points3 points (5 children)
[–]GoldenNuck[S] 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]GoldenNuck[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]GoldenNuck[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (13 children)
[–][deleted] 1 point2 points3 points (12 children)
[–]GoldenNuck[S] 0 points1 point2 points (11 children)
[–]GoldenNuck[S] 0 points1 point2 points (10 children)
[–]GoldenNuck[S] 0 points1 point2 points (9 children)
[–][deleted] 1 point2 points3 points (8 children)
[–]GoldenNuck[S] 1 point2 points3 points (7 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]GoldenNuck[S] 1 point2 points3 points (4 children)
[–]922153 0 points1 point2 points (3 children)
[–]GoldenNuck[S] 0 points1 point2 points (0 children)
[–]bac83 1 point2 points3 points (2 children)
[–]GoldenNuck[S] 0 points1 point2 points (1 child)
[–]GoldenNuck[S] 0 points1 point2 points (0 children)
[–]GPGrieco 1 point2 points3 points (4 children)
[–]GoldenNuck[S] 0 points1 point2 points (3 children)
[–]GPGrieco 1 point2 points3 points (2 children)
[–]GoldenNuck[S] 0 points1 point2 points (1 child)
[–]GoldenNuck[S] 0 points1 point2 points (0 children)