Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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 '10 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. –  brlafreniere Aug 6 '10 at 20:12
1  
Does your wall work from cron? –  Dennis Williamson Aug 6 '10 at 20:46

3 Answers 3

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
1  
Actually all CRON output goes to mail. But if the job doesn't generate output there is no mail. –  BillThor Aug 7 '10 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 '10 at 13:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.