Welcome to the Linux Foundation Forum!

cron running scripts

Hi. I've been reading about cron and I think it's a pretty useful utility. However, I've had a bit of trouble with it running scripts.

I'm running Ubuntu 9.04 with Gnome, by the way.

For example, if I put the following line into my crontab

* * * * * ~/script

(I've tried variations of this using the full path to the script and the $HOME variable.)

And I wait a minute or so, nothing happens. In the System Log Viewer an entry in syslog is added every minute saying that the script was being run, but nothing actually happens. I tried redirecting the output to a file, but the file is blank after the script is run. No errors are shown. I tried "sudo chmod a+rwx" on the script (just in case the script wasn't being run due to permissions issues) but it still isn't working...

Crontab works for other things though. I use it as an alarm clock with

30 5 * * * export DISPLAY=:0 && firefox pandora.com

...and it works as expected.

I'm confused as to why I can't seem to get the program to run the script, or failing that give any sort of error message.

My script, by the way, isn't that complicated, and it works properly when running it regularly...

#!/bin/bash

git add .

git commit -m "Commit on `date`"

Has anyone dealt with this issue before? Any help would be appreciated. :)

~Dennis

Comments

  • mfillpot
    mfillpot Posts: 2,177
    have you tried telling cron to run it as a shell script?

    * * * * * sh ~/script
  • bastib
    bastib Posts: 6
    or you have to cd to the right directory first (in the script)?
  • Rynnkel
    Rynnkel Posts: 5
    @bastib I tried a couple of different scripts using full path names; none of them run.

    I tried doing
    #!/bin/bash
    touch /home/dennis/testing

    And it doesn't run.

    @mfillpot I just tried it with the sh in front. It still doesn't work. :(
  • mfillpot
    mfillpot Posts: 2,177
    what output do you get when you try to run the contents of script or the script itself within a terminal?
  • Rynnkel
    Rynnkel Posts: 5
    @mfillpot

    When I run it from the terminal it works fine.

    Created commit 0c2664e: Commit on Sun May 24 10:58:40 EDT 2009
    1 files changed, 1 insertions(+), 0 deletions(-)
    create mode 100644 .gitignore
  • mfillpot
    mfillpot Posts: 2,177
    I ma unfamiliar with git so bear with me, could this be an issue were you user account that is used to run the job as insufficient rights to git?
  • bastib
    bastib Posts: 6
    Just to be shure...

    Did you try the touch-script with absolute path in crontab?
    Perhaps ~/script.sh expands to /root/script.sh as cron is run as root (?)

    If you tried an absolute path with the git-script and
    just redirected stdout the file is blank because it just tells you that there is no repository on stderr and exits.

    Basti
  • Rynnkel
    Rynnkel Posts: 5
    @mfillpot

    I don't think it's an issue with git. I tried other test scripts as well and none of them worked.

    @bastlib

    I used absolute paths with all the test scripts (and in crontab) and none of them worked. I also tried giving everyone permission to read, write, and execute the script to see if that helped (sudo chmod a+rwx script). It didn't. :(
    ...and just redirected stdout the file is blank because it just tells you that there is no repository on stderr and exits.

    I'm not sure what you mean by this... Could you explain? I'm a noob. >_<;
  • bastib
    bastib Posts: 6
    Hi,

    I thought your script produces an error and you won't see that in the output file if you had an entry like
    * * * * * script.sh > output.txt
    
    because that redirects only stdout.

    The last thing I can imagine is that you have to use the full path of touch like:
    #!/bin/bash
    /usr/bin/touch /home/dennis/delme.txt
    
    and see if that works...

    To see where it is installed type
    which touch
    

    Basti
  • Rynnkel
    Rynnkel Posts: 5
    @bastlib

    Wow, that actually worked. I was using full paths in the crontab and in the script itself for the file to touch, but I wasn't using the commands' full paths.

    Thanks everyone for your help. :)

Categories

Upcoming Training