Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Administrators

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-03-2011, 04:11 AM
Junior Member
 
Posts: 6
Default Problems with zmprov in a cron

I have written a script which contacts another server, downloads (PHP + curl) a list of Zmprov commands and then carries out a PHP exec() to commands to zmprov. After that it pings another file on the remote server to tell the remote server it is complete. This works absolutely fine when I run it with
Code:
php -f /path/to/fetch_commands.zmp
However when I put it in the zimbra users crontab, for some reason the zmprov part fails with no error.

Here is the script:
Code:
<?php
$sourceUrl = 'https://secure.domain.com/tools/zimbra.zmp';
$dumpPath = '/tmp/zimbra-commands.zmp';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $sourceUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);

echo "Fetching Commands...\r\n";
$result = curl_exec($ch);

// Only write to file if needed
if(strlen($result) > 0) {
	
	$fp = fopen($dumpPath, 'a');
	fwrite($fp, $result);
	fclose($fp);
	
	// Now we've written the commands, we need to push them to zmprov
	echo "Setting up accounts..";
	exec("zmprov < /tmp/zimbra-commands.zmp"); // This is FAILING when ran from a cron
	
	// Delete them as we don't need to do them again.
	unlink($dumpPath);

	// Now we need to ask the server to clear out the commands
	curl_setopt($ch, CURLOPT_URL, 'https://secure.domain.com/tools/zimbra-post-update.php');
	curl_exec($ch);
}

curl_close($ch);
Here is the cronjob and how I set it up:
Code:
sudo su zimbra
crontab -e

*/10 * * * * php -f /tmp/fetch_commands.php
The PHP script definitely runs, as it contacts my post-update file on my server and it's logged.
Reply With Quote
  #2 (permalink)  
Old 11-03-2011, 12:58 PM
Advanced Member
 
Posts: 178
Default

I don't use PHP scripts myself, but are there missing environment variables which may be included when running as the Zimbra user (some of what is in .bashrc or .bash_profile) but not when running the cronjobs (which I think run in sh, not bash)?
__________________
---
Paul Chauvet
State University of New York at New Paltz
Reply With Quote
  #3 (permalink)  
Old 11-04-2011, 02:46 AM
Junior Member
 
Posts: 6
Default

Quote:
Originally Posted by chauvetp View Post
I don't use PHP scripts myself, but are there missing environment variables which may be included when running as the Zimbra user (some of what is in .bashrc or .bash_profile) but not when running the cronjobs (which I think run in sh, not bash)?
Yeah I resolved it, the problem was the path to zmprov, I needed the entire absolute path to it. It also didn't help I was logging the cron errors properly!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.