I have a python script which which calls bash script to get list of all new directories created in last hour. Python script is executable.
#!/usr/bin/python
import subprocess
import os
import dicom
import time
dire = '.'
directories = subprocess.check_output(
['find', '/dicom', '-maxdepth', '1', '-type', 'd', '-mmin', '-120', '-type', 'd', '-mmin', '+5']
).splitlines()
number_of_directories = len(directories)
b_new = 0
for n in range(1,number_of_directories):
dire_str = str(directories[n])
#dire_str = str(dire_str)
print(dire_str)
for dirpath,dirnames,filenames in os.walk(dire_str,topdown=True):
a =1
for filename in filenames:
print(dirpath)
if filename[-4:] == '.dcm':
firstfilename = os.path.join(dirpath, filename)
dcm_info = dicom.read_file(firstfilename, force=True)
if dcm_info[0x0019, 0x109c].value == 'epiRTme':
dirpath_nii = dirpath[:-4]
a = dirpath[-3:]
a = int(a)
os.chdir(dirpath_nii)
subprocess.call('/home/sdcme/bin/nii_mdir_sdcme %s %s' % (a, a), shell=True)
break
break
Apparently if i call this python script standalone on command prompt, it works fine but when i set it to run after 60 min on crontab, the script throws following error:
Traceback (most recent call last):
File "/home/sdcme/Final_concat_sdcme.py", line 9, in <module>
['find', '/dicom', '-maxdepth', '1', '-type', 'd', '-mmin', '-120', '-type', 'd', '-mmin', '+5']
File "/usr/lib64/python2.7/subprocess.py", line 530, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib64/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1201, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
~
Crontab Script
*/59 * * * * Final_concat_sdcme.py &>~concatenation.log
can some one point out what is the problem here.. Appreciate help a lot.
EDIT:
Cron output LOG Error:
niidicom_sdcme: Command not found.
niidicom_sdcme: Command not found.
niidicom_sdcme: Command not found.
niidicom_sdcme: Command not found.
niidicom_sdcme: Command not found.
niidicom_sdcme: Command not found.
Actually my python script calls nii_mdir_sdcme script calls niidicom_sdcme. When i run above script independently on terminal there is no error but when cron job cals the above script->nii_mdir_sdcme->niidicom_sdcme then there seems to be problem .
PATHvariable - it's required to find system and user binaries. Instead, use the full path to the script and output file in the crontab. e.g./home/sdcme/Findal_concat_sdcme