Here's a perl script that works when I run it manually. But when I run it via cron, it won't create the directory. But worse than that, an email isn't sent to the account running the job. So I'm not getting an error, but it does work when I run it manually. If I put an obvious error in the script, cron does generate an email giving me the STDERR. What could it be? === Al #!/usr/bin/perl ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # Above functions, "time" and "localtime", return weird $year and $month # Need to be converted to become human readable $year = $year + 1900; $mon = $mon + 1; # Want $mday and $mon to be 2 digits, with leading zero if necessary $mday = "0" . $mday if $mday < 10; $mon = "0" . $mon if $mon < 10; # Second parameter is mask in octal chdir "/ora-local/db-test-backups"; mkdir "${year}_${mon}_${mday}", \00022; ####End perl script
hey al... what are the privs that the cron is being run as. the cron should be root. what are the acls for the dir that you're writing to?? it's probably a simple priv/acl issue.... -----Original Message----- From: centos-bounces at centos.org [mailto:centos-bounces at centos.org]On Behalf Of Al Sparks Sent: Tuesday, September 16, 2008 5:01 PM To: Centos List Subject: [CentOS] cron job not working Here's a perl script that works when I run it manually. But when I run it via cron, it won't create the directory. But worse than that, an email isn't sent to the account running the job. So I'm not getting an error, but it does work when I run it manually. If I put an obvious error in the script, cron does generate an email giving me the STDERR. What could it be? === Al #!/usr/bin/perl ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # Above functions, "time" and "localtime", return weird $year and $month # Need to be converted to become human readable $year = $year + 1900; $mon = $mon + 1; # Want $mday and $mon to be 2 digits, with leading zero if necessary $mday = "0" . $mday if $mday < 10; $mon = "0" . $mon if $mon < 10; # Second parameter is mask in octal chdir "/ora-local/db-test-backups"; mkdir "${year}_${mon}_${mday}", \00022; ####End perl script _______________________________________________ CentOS mailing list CentOS at centos.org http://lists.centos.org/mailman/listinfo/centos
Al Sparks wrote:> Here's a perl script that works when I run it manually. But when I > run it via cron, it won't create the directory. But worse than that, > an email isn't sent to the account running the job. So I'm not > getting an error, but it does work when I run it manually. > > If I put an obvious error in the script, cron does generate an > email giving me the STDERR. > > What could it be? > === Al > > #!/usr/bin/perl > > ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); > > # Above functions, "time" and "localtime", return weird $year and $month > # Need to be converted to become human readable > > $year = $year + 1900; > $mon = $mon + 1; > > # Want $mday and $mon to be 2 digits, with leading zero if necessary > > $mday = "0" . $mday if $mday < 10; > $mon = "0" . $mon if $mon < 10; > > # Second parameter is mask in octal > > chdir "/ora-local/db-test-backups"; > mkdir "${year}_${mon}_${mday}", \00022; > ####End perl script >Probably a permissions problem, as has been noted. What I can't understand is how the problem came to be so complicated. This, run as a root cron job, will produce the desired directory: #!/bin/bash mkdir -p /ora-local/db-test-backups/`date +%Y"_"%m"_"%d` ...without the adjustments in the perl script. AAMOF, it's even simpler if you can tolerate hyphen separators rather than underscores. (date +%F)
The crond itself is being run as root. I am running the cron job as another user that has permission to run cron jobs. Note that if I change the program to print output to STOUT and run through cron, I get an email in that account with that output. === Al ----- Original Message ---- From: bruce <bedouglas at earthlink.net> To: CentOS mailing list <centos at centos.org> Sent: Tuesday, September 16, 2008 4:25:23 PM Subject: RE: [CentOS] cron job not working hey al... what are the privs that the cron is being run as. the cron should be root. what are the acls for the dir that you're writing to?? it's probably a simple priv/acl issue.... -----Original Message----- From: centos-bounces at centos.org [mailto:centos-bounces at centos.org]On Behalf Of Al Sparks Sent: Tuesday, September 16, 2008 5:01 PM To: Centos List Subject: [CentOS] cron job not working Here's a perl script that works when I run it manually. But when I run it via cron, it won't create the directory. But worse than that, an email isn't sent to the account running the job. So I'm not getting an error, but it does work when I run it manually. If I put an obvious error in the script, cron does generate an email giving me the STDERR. What could it be? === Al #!/usr/bin/perl ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # Above functions, "time" and "localtime", return weird $year and $month # Need to be converted to become human readable $year = $year + 1900; $mon = $mon + 1; # Want $mday and $mon to be 2 digits, with leading zero if necessary $mday = "0" . $mday if $mday < 10; $mon = "0" . $mon if $mon < 10; # Second parameter is mask in octal chdir "/ora-local/db-test-backups"; mkdir "${year}_${mon}_${mday}", \00022; ####End perl script _______________________________________________ CentOS mailing list CentOS at centos.org http://lists.centos.org/mailman/listinfo/centos _______________________________________________ CentOS mailing list CentOS at centos.org http://lists.centos.org/mailman/listinfo/centos
> Probably a permissions problem, as has been noted. What I can't > understand is how the problem came to be so complicated. This, > run as a root cron job, will produce the desired directory: > > #!/bin/bash > mkdir -p /ora-local/db-test-backups/`date +%Y"_"%m"_"%d` > > ...without the adjustments in the perl script. AAMOF, it's even > simpler if you can tolerate hyphen separators rather than > underscores. (date +%F)I'll give that a shot. Note that I have not been running this as root (though crond is running as root). Most of the time, if it's a permissions problem, crond will send an email telling me it's a permissions problem. === Al