Howdy, Stranger!

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


Running cronjob on CentOS
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.

Running cronjob on CentOS

I have a problem running a cronjob on CentOS 6.
I'd like to run a shell-script that gets my home IP and updates the iptables on my VPS.
The script works without problems when started manually.

Now, I want to do the job with cron every 20 or so minutes. I started "crontab -e" and added the following line:

*/20 * * * * /bin/bash /etc/get_ip.sh

The get_ip.sh is exectuable, changed the ownerhip via "chmod +x get_ip.sh", owner is now root (same user the cron is created for).

The problem is: the script isn't executed by cron and I dunno why. There are no errorlogs in /var/log or something, seems it just doesn't work.
Any ideas what the problem may be?

Comments

  • How if just like this:

    */20 * * * * /etc/get_ip.sh
  • Also no luck :(
    This was the first I tried. Even if BASH is defined in the script, to be sure it's executed I added it to the cronlist. Both ways don't work. Crond is running, so I am running out of ideas what causes this problem.

  • The cron log is in /var/log/cron, you should find your scripts there.

    Thanked by 1german_psycho
  • No logfile, either :(
    Would cron create a log, even if it exited without errors? Haven't ever checked this..
    Maybe I should just add a job where it creates a file or similiar, just to check if cron executes at all.

  • @german_psycho said:
    No logfile, either :(
    Would cron create a log, even if it exited without errors? Haven't ever checked this..
    Maybe I should just add a job where it creates a file or similiar, just to check if cron executes at all.

    Type "env" in ssh and look for a line like this:

    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

    Then add the entire line to the top of crontab -e after the hashed out sections and before your scripts line.

    Thanked by 2german_psycho Blanoz
  • Yeah, it finally works.
    Thanks alot, guys!

Sign In or Register to comment.