Results 1 to 3 of 3

Thread: Problems with zmprov in a cron

  1. #1
    Dunhamzzz is offline Junior Member
    Join Date
    Oct 2011
    Posts
    6
    Rep Power
    3

    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.

  2. #2
    chauvetp is offline Elite Member
    Join Date
    Apr 2008
    Location
    New Paltz, NY
    Posts
    309
    Rep Power
    7

    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

  3. #3
    Dunhamzzz is offline Junior Member
    Join Date
    Oct 2011
    Posts
    6
    Rep Power
    3

    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!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problems with ZMPROV command
    By hsp896 in forum Administrators
    Replies: 5
    Last Post: 07-14-2011, 11:10 AM
  2. [SOLVED] 2 problems creating account with zmprov
    By cyber7 in forum Administrators
    Replies: 4
    Last Post: 11-07-2010, 10:16 PM
  3. Unable to script zmprov changes completely
    By todd_dsm in forum Installation
    Replies: 1
    Last Post: 12-16-2009, 07:39 AM
  4. Getting problems in FC4 while instalation
    By kitty_bhoo in forum Installation
    Replies: 13
    Last Post: 09-12-2006, 10:34 PM
  5. Problems with Zimbra Cron Jobs
    By soxfan in forum Administrators
    Replies: 9
    Last Post: 08-22-2006, 09:02 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •