Crontab Problem


#1

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?


#2

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

755 is good.


#3

#!/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.


#4

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.


#5

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


#6

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.


#7

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


#8

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


#9

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.