I have an executable bash script (.sh
) which should be run 2 python scripts consistently (only when first is successfully finished then the second one will be started), run_script.sh
has the following view:
#!/bin/bash
#!/usr/bin/python3
scripts='/path/to/file/file1.py /path/to/file/file2.py'
for s in $scripts
do
echo $s
/usr/bin/python3 $s
done
As a scheduler I use crontab job
:
26 14 10-23 * * cd /path/to/file/ && /path/to/file/run_script.sh >> /home/log/crontab_LOG.log 2>&1
In process of data aggregation in python scripts I use .pickle
files.
But, in result of execution the suggested python scripts (file1.py
and file2.py
) by .sh
file, I received and error:
PermissionError [Errno 13 ] Permission denied: '/path/to/file/example.pickle'
btw: example.pickle
file is created in process of execute file1.py
,not out of run where it used.
When try to execute sh run_script.sh
by terminal without any scheduler, there is no any error to permissions. So, result is success.
I also try to search my question, but it was not success. (Permission denied for Python script using Bash?), IO Error while storing data in pickle
The question is how I can set the the root permission by bash script to required python scripts?
It was fixed by usage approach with Path
:
from pathlib import Path
example_pickle = Path('logs/example_pickle'+datetime.now()+'.pickle')
Thanks everyone for the inspired ideas:)