2016-04-30 46 views
0

我只是用cron的写perl程序自动化的目的克朗自动化运行perl程序不工作?

我cron是

*/30 * * * * perl /path/to/cron.pl 

cron.pl

#!/usr/bin/perl 
use strict; 
use warnings; 

`/usr/bin/perl /path/to/run.pl`; 

里面的代码我使用反勾运行其他的Perl程序。

run.pl

#!/usr/bin/perl 
use strict; 
use warnings; 

open(FL,">text.txt") or die $!; 

print FL "hi"; 

close FL; 

每当我跑cron.pl它创造 “的text.txt” 文件。但是cron运行程序cron.pl正在运行,但是run.pl没有运行。任何人都可以告诉我我在代码中做了什么错误吗?

+4

强制性评论:始终在每个Perl脚本的顶部放置'use strict;'和'use warnings;'。你的问题可能是由于在调用'run.pl'时使用相对路径。尝试使用Perl解释器和脚本的绝对路径:'/ usr/bin/perl/absolute/path/to/run.pl'; – bart

+0

@bart感谢您的评论。我使用严格的使用警告,然后我在该程序中添加了绝对路径,但仍然无法正常工作。 – SSN

+2

如何知道run.pl没有被执行?该脚本以读取模式打开文件句柄,但下一行尝试写入文件句柄,这不会起作用。 –

回答

0

cron行必须包含完整的可执行文件的路径!

*/30 * * * * /usr/bin/perl /path/to/cron.pl