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:
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
1 个解决方案
#1
-1
Cron needs the correct PATHs:
Cron需要正确的PATH:
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
#1
-1
Cron needs the correct PATHs:
Cron需要正确的PATH:
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