简体   繁体   中英

Schedule python script with crontab, shutil.move doesn't work

Hi I schedule my script with cron.d, everything work except a function for move some files from a folder to another.

the function is:

def move_imported_file():
    all_file=get_file()
    for files in all_file:
        #print (files)
        shutil.move("/mnt/test-file/"+files, "/mnt/test-file/imported/"+files)

my cron.d file is this:

10 12 * * * root cd /usr/local/sbin/import-file/ && ./myscript.py

If i try to run manually the script, the function move all_file, but if I run the cron.d task, nothing happens

There is any possibility to have a log of what the function are doing?

Thanks


get_file:

def get_file():
    my_file = []
    os.chdir("/mnt/test-file")
    files = glob.glob('*.ics')
    for file in files:
        my_file.append(file)
        #print (my_file)

    return my_file

Cron needs the correct PATHs:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/snap/bin

0 15 * * * root cd /usr/local/sbin/import-file/ && ./myscript.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM