LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cron.hourly : return code 127 (https://www.linuxquestions.org/questions/linux-newbie-8/cron-hourly-return-code-127-a-4175444414/)

barathan 01-06-2013 07:58 PM

cron.hourly : return code 127
 
hello all,

i have created a simple python script that will move log files from one linux machine to another linux machine. i placed this script in cron.hourly (my machine is LINUX Open Suse). eventually, my script doesnt run hourly. checked in /var/mail/root, saw below message :

running hourly cronjob scripts

SCRIPT: FILEMOV02.py exited with RETURNCODE = 127.
SCRIPT: output (stdout && stderr) follows

nice: /etc/cron.hourly/FILEMOV02.py: No such file or directory
SCRIPT: FILEMOV02.py
------- END OF OUTPUT


could anyone help me please? below is my python script :


#!/usr/bin/python

import os
import time
import glob

filePath = r"/usr/local/testlogs/parse/*.*"
serverPath = r"/usr/local/testlogs/DB_parse"

try :
files = glob.glob(filePath)
for f in files :
os.system("scp "+f+" root@192.168.10.1:"+serverPath)
time.sleep(1) #delay 1 sec before file gets deleted one by one
os.remove(f)

except OSError:
print "parse directory is missing!!"


-thanks-

barathan 01-07-2013 05:47 AM

adding more info : this is my crontab

SHELL=/bin/sh
PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin
MAILTO=root
#
# check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly
#
-*/27 * * * * root test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null 2>&1

linosaurusroot 01-07-2013 06:11 AM

Quote:

Originally Posted by barathan (Post 4864218)
nice: /etc/cron.hourly/FILEMOV02.py: No such file or directory

Does /etc/cron.hourly/FILEMOV02.py exist? Can it be run from a shell prompt?

barathan 01-07-2013 06:15 AM

hi there!

yes, this file exists in /etc/cron.hourly and i gave 777 permission for this file. it works fine on the terminal when i run "python FILEMOV02.py"
i think there's something wrong with the environment. but since i'm a newbie, i need step by step guidance.

-thanks-

linosaurusroot 01-07-2013 06:39 AM

What about calling "/etc/cron.hourly/FILEMOV02.py" on its own? Does /usr/bin/python exist?

barathan 01-07-2013 08:42 PM

yes, /usr/bin/python exist. how do you want me to call /etc/cron.hourly/FILEMOV02.py? i was able able to go to directory /etc/cron.hourly and run the script by typing python FILEMOV02.py, and didnt see any issue

barathan 01-07-2013 09:53 PM

ok, so now in gnome terminal, i typed "/etc/cron.hourly/FILEMOVE02.py" and got below error message :

-bash: /etc/cron.hourly/FILEMOV02.py: /usr/bin/python^M: bad interpreter: No such file or directory

any idea what is this please?

rknichols 01-07-2013 10:32 PM

The file was created by a Windows/DOS editor and has DOS-style line endings (CR-LF). You need to run dos2unix on the file to change to Unix-style endings (LF).

barathan 01-08-2013 12:05 AM

absolutely! i just solved this :

in gnome terminal, type "cat FILEMOV02.py | col -b > FILEMOV03.py"

i dont see the ^M error message anymore! thank very much everybody!


All times are GMT -5. The time now is 09:21 PM.