Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Shell script runs fine by hand, but not automatically in cron.hourly directory?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Shell script runs fine by hand, but not automatically in cron.hourly directory?

djvdorpdjvdorp Member
edited March 2012 in Help

Hi all,

I recently fetched/created some scripts for auto hourly mysql and public_html backup, including an part where it auto-rsyncs to a remote box. Running these 3 separate scripts by hand works perfectly fine, but I just checked and none of them are being run by the cron thingie? they have been chmodded +x and placed in cron.hourly
Distro is ubuntu 11.10 server, which has that cron config by default i believe.

Please help me out?

Comments

  • KuJoeKuJoe Member, Host Rep

    You might need to specify the full location of the scripts being run (i.e /usr/bin/rsync).

  • I found one of my cron jobs never worked until I put a cd /directory/to/script && sh run script.sh as the cron.

  • I had the same, i just put the full path to it
    That should be, works for me

  • tommytommy Member

    you should put full path of your scripts on cron
    ex :
    /home/tommy/Scripts/Gambas/sql.sh

    and make sure crontab have permission to execute your script.

  • DerekDerek Member

    I found it is easier to just program them in php and then just php CLI to back them up. mysqldump+timestamp > rsync.

    Pretty simple.

  • @KuJoe said: You might need to specify the full location of the scripts being run (i.e /usr/bin/rsync).

    This one was pretty useful! I found out that the ubuntu cron.daily, cron.hourly and cron.weekly dirs aren't real 'cronjobs' but run by a program named run-parts.
    We can check which things will be run from that directories by running the command:
    run-parts --test /etc/cron.hourly

    Also, the files must include a shebang (I did that) and have no extension.
    Found this and more info here:
    http://ubuntuforums.org/showpost.php?p=10154736&postcount=4

  • jon617jon617 Veteran

    Always specify full paths in the script and when calling from cron. I even go as far as to reference most programs in full path (like /bin/grep instead of just grep) because I don't always trust the PATH. Test cron jobs by su'ing to the user it runs as, cd into that user's home directory, and run the script. Any errors you see there should also be seen when the cron runs.

Sign In or Register to comment.