On Sunday, September 22, 2002, at 12:30  pm, douglas mcdonald wrote:

> I'm having a problem running a backup script through cron. The script 
> runs perfectly from the command line, but when I run it through cron I 
> end up with an empty file. This is presumably because the "mysqldump" 
> is not recognized as a sh command (which it's not, understandably).

>  What I need is a way to access the mysqldump app through crontab.

if it's an app then that translates to a process for perl so you can 
open pipes ('|') in or out to the process pretty much the way you open 
input or output flows:

#!/usr/bin/perl -w

## this script copies today's date to and from the clipboard ##

use strict;

my(@temp,$temp,$date);
open (CLIPBOARDOUT, "|pbcopy");
@temp=(localtime (time));
print CLIPBOARDOUT sprintf  ("%02d/%02d/%02d", $temp[3], ($temp[4]+1), 
($temp[5]%100));
close (CLIPBOARDOUT);

open (CLIPBOARDIN, "pbpaste|");
$date =<CLIPBOARDIN>;

print "\$date is: ",$date,"\n";int CLIPBOARD sprintf  ("%02d/%02d/%02d", 
$temp[3], ($temp[4]+1), ($temp[5]%100));

here the perl script sends the data to the process which manages the 
clipboard.

How ever if the app isn't running when you call for it, then obviously 
you aren't going to get what you expect.

Also I suggest you check for return values which might give you some 
idea as to what's going wrong:

#!/usr/bin/perl-w

($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = 
localtime();
$mon++;
$year += 1900;
$date = "dbname_${year}_${mon}_${mday}_${min}";
$flag= `mysqldump -umysqluser -pmysqlpassword --flush-logs --lock-tables 
--databases dbname > /library/webserver/data/$date.sql`;
open (OUT,/path/to/log)||die $!;
print OUT  "\$flag is=",$flag,"\n";

Reply via email to