crontab Problem

crontab Problem

Posted by: Koldark
Posted on: 2007-02-13 22:52:00

I am trying to get a scheduled bash script to run. The line is: "*/30 * * * * /home/username/planet/technews.sh". I have tried a few other variations as well. I keep getting the error "/bin/sh: line 1: /home/username/planet/technews.sh
: No such file or directory". This works fine on the command line but I can't get it work through crontab.

Any ideas? For testing, because of the problems, I set the permissions to 777 (bad I know). What is the needed permissions? Could this be the problem?

Re: crontab Problem

Posted by: Se7enOf9
Posted on: 2007-02-14 03:20:00

What is line 1? Cron environment has less PATH than command line. Not find all, php as example.

755 is good.

Re: crontab Problem

Posted by: Koldark
Posted on: 2007-02-14 06:21:00

#!/bin/bash
cd
cd planet
python planet.py technews/config.ini

Is my script. Again, works fine on the command line. I am not sure what you where saying.

Re: crontab Problem

Posted by: Se7enOf9
Posted on: 2007-02-14 07:31:00

Define all paths I suggest.

#!/bin/bash
cd /home/user/path/to/planet
/path/to/python /path/to/planet.py /home/user/full/path/to/technews/config.ini

or use $HOME/... where you can.

Crontab knows few environment, like $PATH. Command line knows more, finds more.

Re: crontab Problem

Posted by: matttail
Posted on: 2007-02-14 12:20:00

I think that this problem is related to cron not finding the file rather than a problem with your script. Are you sure that you're giving the correct path to the script, remembering the fact that it's CasESenSiTivE?



--Matttail
art.googlies.net - personal website

Re: crontab Problem

Posted by: Koldark
Posted on: 2007-02-14 13:25:00

Like I have said before. I can run the script on the command line. As soon as I put in in Cron, it errors out.

Re: crontab Problem

Posted by: wholly
Posted on: 2007-02-14 20:25:00

Remember that cron jobs don't by default run with the same shell environment as a logged in user. It may be necessary to "source" your ".profile" and/or ".bashrc" or whatever shell environment is necessary... BUT

The correct way to do it is to find out what is necessary and only include the paths you need or as an example showed above, explicitly state your files. The reason is to minimize the chance of an exploit being introduced along your path.

Hope this helps.

Wholly

Re: crontab Problem

Posted by: Koldark
Posted on: 2007-02-16 06:24:00

After contacting support, they said that the end-of-line character was wrong. It is working again. Thanks for the help guys.

Re: crontab Problem

Posted by: wholly
Posted on: 2007-02-16 06:41:00

Of course line termination could also be an issue... (grin) It certainly explains why the error was on line #1.

Wholly - IS NOT MY PROMO CODE. Even worse, I don't get any credit for it. Use WhollyMindless for full credit. I'm really disappointed in someone.

Tags: crontabbash scriptline 1variationssh