简体   繁体   English

使用crontab计划python脚本,shutil.move不起作用

[英]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. 嗨,我使用cron.d安排了脚本,除了将某些文件从文件夹移动到另一个文件的功能之外,其他所有功能都可以正常工作。

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: 我的cron.d文件是这样的:

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 如果我尝试手动运行脚本,该函数将移动all_file,但是如果我运行cron.d任务,则不会发生任何事情

There is any possibility to have a log of what the function are doing? 是否有可能记录该功能的作用?

Thanks 谢谢


get_file: 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: Cron需要正确的路径:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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