0

I have one cron job installed but not running. I installed it with crontab -e and entered the following.

0 12 * * * /var/www/drupal/scripts/dump_sites
* * * * * wall /tmp/test

I put the second command for testing purposes. There is indeed a file /tmp/test, it simply has "this is a test" in it.

When I exit crontab -e I receive no error messages. There are no log files for cron in /var/log/. I stopped cron with service cron stop and tried starting it with cron -L 2 to get better debug output, but there are still no logs.

I've ran /var/www/drupal/scripts/dump_sites manually and I get the expected behavior, i.e. output files appear where I want them to. When I try with cron, I do not get the expected behavior.

When I do ps aux | grep cron I can see it with an associated process ID.

I gave up on cron momentarily and tried anacron. ps aux | grep cron now yields the following. However; my dump_sites script still doesn't run.

devcampus :: /var/www/drupal » ps aux | grep cron   
root     15635  0.0  0.1  12440   928 ?        Ss   11:59   0:00 anacron -f
root     15816  0.0  0.1   4092   608 ?        S    12:04   0:00 /bin/sh -c nice run-parts --report /etc/cron.daily
root     15818  0.0  0.1   3996   620 ?        SN   12:04   0:00 run-parts --report /etc/cron.daily
root     15825  0.0  0.1   4092   680 ?        SN   12:04   0:00 /bin/sh /etc/cron.daily/apt

My /etc/anacrontab file looks like this.

# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# These replace cron's entries
1       5       cron.daily       nice run-parts --report /etc/cron.daily
7       10      cron.weekly      nice run-parts --report /etc/cron.weekly
@monthly        15      cron.monthly nice run-parts --report /etc/cron.monthly

# period  delay  job-identifier  command
@daily    14     backup          /var/www/drupal/scripts/dump_sites

I'm running Ubuntu 10.04, and I believe this box is running on a Xen virtualization server.

devcampus :: /var/www/drup
2.6.32-23-server

Update: apparently it's working with anacron.


As per request, here's dump_sites:

#!/usr/bin/env ruby

DRUPAL_ROOT = File.expand_path(File.dirname(__FILE__) + '/../')
SITES_ROOT = File.join(DRUPAL_ROOT, 'sites')
CONFIG_FILES = Dir.glob(File.join(SITES_ROOT, "*", "dbconfig.php"))

databases = CONFIG_FILES.map do |cf|
  contents = File.read(cf)
  contents =~ /dbname='(.*)'/ ? $1 : nil
end

databases.uniq!
databases.sort!

databases.each do |db|
  file_name = File.join(DRUPAL_ROOT, "db_dumps", "#{db}_#{Time.now.strftime("%Y-%m-%d-%H-%M-%S")}.sql")
  `mysqldump -uusername -ppassword #{db} > #{file_name}`
end

Just a plain old ruby script.

3
  • I'm not familiar with drupal CMS could you post the content of dump_sites ? depending of it is content the problem could be the cron not having the set of env you have as a user resulting on the script not being executed.
    – Prix
    Aug 6, 2010 at 18:20
  • It's just a plain old Ruby script, but I've added there anyway. Perhaps cron isn't able to see mysqldump or something. Aug 6, 2010 at 20:12
  • 1
    Does your wall work from cron? Aug 6, 2010 at 20:46

3 Answers 3

1

Your cron runs should be logged in /var/log/syslog. You should be getting email if there are errors.

Usually when a script runs from the command line and won't from cron it's because of a difference in environment. It's a good idea to set the PATH variable explicitly and/or use full paths to all files and executables. I see that you've done that in your crontab entry, but you should check the script itself.

In addition to PATH there may be other environment dependencies that your script has. Without see it, I can't guess what they might be.

1

Remember that cron scripts don't run with your full user environment (PATH, etc.), so it's quite possible that cron is running your script, but that the script isn't working.

0

cron errors usually go to mail. Have you tried checking that? Just type in mail at your command line and it you might just see a list of messages from cron.

2
  • 1
    Actually all CRON output goes to mail. But if the job doesn't generate output there is no mail.
    – BillThor
    Aug 7, 2010 at 16:31
  • Oh ok. Thanks! I guess I didn't notice because, usually, my std output goes to a file or something.
    – Sagar
    Aug 9, 2010 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .