Reputation: 85
The script is running from terminal but not from crontab.The script code and error i am getting is written below :
Script
#!/usr/bin/python
import subprocess
subprocess.call(['touch','yahoo.txt'])
Error from Crontab mail
From [email protected] Mon Jul 22 21:10:05 2013
Return-Path: <[email protected]>
Received: from vps.server.com (localhost [127.0.0.1])
by vps.server.com (8.14.4/8.14.4/Debian-2ubuntu2) with ESMTP id r6MHA3ll002017
for <[email protected]>; Mon, 22 Jul 2013 21:10:03 +0400
Received: (from root@localhost)
by vps.server.com (8.14.4/8.14.4/Submit) id r6MHA1sr002016
for root; Mon, 22 Jul 2013 21:10:01 +0400
Date: Mon, 22 Jul 2013 21:10:01 +0400
Message-Id: <[email protected]>
From: [email protected] (Cron Daemon)
To: [email protected]
Subject: Cron <root@vps> cd /root/; python mkdir.py
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
': [Errno 2] No such file or directory
Upvotes: 0
Views: 1142
Reputation: 489498
You have a literal carriage return in your command line (created by some errant editor or a Windows user or some such):
$ python nosuchfile.py
python: can't open file 'nosuchfile.py': [Errno 2] No such file or directory
$ python nosuchfile.py^M
': [Errno 2] No such file or directory
(the ^M above, I created by typing control-V control-M, where control-V is my "lnext" character).
The error message prints the file name, including the carriage return, and then the rest of the characters overwrite the initial part of the error. Note that if you make the file name just a bit longer, you'll see part of it:
$ python verylongfilenamethatdoesnotexist.py^M
': [Errno 2] No such file or directoryamethatdoesnotexist.py
To fix it, open the crontab entry/file with an editor that lets you take out that bogus carriage-return.
Upvotes: 2