I have written a python script.py in my ~home/ directory which calls other python scripts located ~home/bin. When i run script.py i am able to run it successfully but when i schedule script.py in crontab, script.py is not able to call script from bin directory.
Crontab script looks like this:
*/59 * * * * script.py &>~concatenation.log
script.py calls another script as following:
subprocess.call('/home/sdcme/bin/nii_mdir_sdcme %s %s' % (a, a), shell=True)
can some one point it out why script.py is not able to call the other script. I suspect the problem is with PATh variable or other such thing but dont have nay idea how i should troubleshoot this..
Thanks!
Edit: nii_mdir_sdcme script calls another script niidicom_sdcme located in the same bin directory: Crontab mail, shows following error mail -
niidicom_sdcme: Command not found.
niidicom_sdcme: Command not found.
Summary:
cronatab-> script.py -> nii_mdir_sdcme -> niidicom_sdcme the problem is nii_mdir_sdcme is not able to call niidicom_sdcme. But when i run script.py independently on command prompt everything works fine..
nii_mdir_sdcme code:
#!/bin/tcsh
if ($#argv < 2) then
echo "Usage: nii_mdir_sdcme start_dir# end_dir#"
exit
else
set start = $argv[1]
set end = $argv[2]
if ( ! -d ./medata ) then
sudo mkdir ./medata
endif
sudo chown sdcme ./medata
sudo chgrp users ./medata
set i = $start
while ( $i <= $end )
echo " "
if ( $i < 10 ) then
echo "Entering 000$i..."
cd 000$i
sudo chmod 777 .
niidicom_sdcme run0$i
#mv *+orig.* ../medata
sudo chmod 755 .
else
echo "Entering 00$i..."
cd 00$i
sudo chmod 777 .
niidicom_sdcme run$i
#mv *+orig.* ../medata
sudo chmod 755 .
endif
cd ..
@ i++
end
endif
mailormutt.niidicom_sdcmeis not run? The error looks like printed byniidicom_sdcmeitself i.e., it can't findrun0$iorrun$icommands (sh, bash, zsh produce different error messages here). Unrelated:&>looks likebashsyntax (set SHELL explicitly in the crontab),subprocess.calluses/bin/shifshell=True(you could useexecutableparameter to choose other shell), your script runs/bin/tcsh. Make sure there are no error due to difference in syntax between the shells.