954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

crontab output

hi,
iam fairly new at unix.what iam trying to do is iam running a perl script through crontab.the problem is iam getting an error message on my mail.
this is the crontab file:
24 16 22 1 * perl /rishi/s-branch/perl1/perl/filecomp.pl


this is the content of my perl file
#!usr/local/bin/perl
@comp=`diff -r -s /tpf106/data2/cis_web/cis3/cis3.11/work/rishi/s-branch/perl1 /tpf106/data2/cis_web/cis3/cis3.11/work/rishi/s
-branch/doc>file1.txt`;
@text=`grep -n "Only in /tpf106" file1.txt>only.txt`;
@show=`cat only.txt`;
print @show;

wiz83
Newbie Poster
17 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

don't think you're supposed to activate it by perl
the script has the interpretor line in it

change the crontab line to just the path to the script

also, is the script working when run from the shell manually?

DimaYasny
Posting Virtuoso
Moderator
1,777 posts since Jan 2007
Reputation Points: 183
Solved Threads: 89
 

don't think you're supposed to activate it by perl the script has the interpretor line in it

change the crontab line to just the path to the script

also, is the script working when run from the shell manually?

script is working when i run it from the shell manually,and it runs only when i activate it through perl filecomp.pl

wiz83
Newbie Poster
17 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

is the script executable?

DimaYasny
Posting Virtuoso
Moderator
1,777 posts since Jan 2007
Reputation Points: 183
Solved Threads: 89
 

chmod the script 755, and if you want to run it as

perl scriptname

in crontab, just be sure to give the absolute path to perl in your entry, like:

/usr/bin/perl scriptname

and it should work either way

Hope that helps :)

, Mike

eggi
Posting Pro in Training
400 posts since Oct 2007
Reputation Points: 102
Solved Threads: 47
 

25 01 23 1 * perl /tpf106/data2/cis_web/cis3/cis3.11/work/rishi/s-branch/perl1/perl/filecomp.pl>file3.txt
i have given the absolute path i have also made the script executable.its still not working.infact no perl script is running.but when i run them manually they seem to work fine.

content of filecomp.pl
#!usr/local/bin/perl
@comp=`diff -r -s /tpf106/data2/cis_web/cis3/cis3.11/work/rishi/s-branch/perl1 /tpf106/data2/cis_web/cis3/cis3.11/work/rishi/s
-branch/doc>file1.txt`;
@text=`grep -n "Only in /tpf106" file1.txt>only.txt`;
@show=`cat only.txt`;
print @show;

wiz83
Newbie Poster
17 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

after some googling, seems like perl scripts have trouble running from crontab.

try to create a bash script which will launch the perl script, and make the bash script run from crontab

DimaYasny
Posting Virtuoso
Moderator
1,777 posts since Jan 2007
Reputation Points: 183
Solved Threads: 89
 

after some googling, seems like perl scripts have trouble running from crontab.

try to create a bash script which will launch the perl script, and make the bash script run from crontab

cant i just run it through crontab,directly.i know it happens

wiz83
Newbie Poster
17 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

well it appears cron environment is not the same as the normal environment.

try to run the script with all absolute paths:
/usr/local/bin/perl /rishi/s-branch/perl1/perl/filecomp.pl

DimaYasny
Posting Virtuoso
Moderator
1,777 posts since Jan 2007
Reputation Points: 183
Solved Threads: 89
 

still not working

wiz83
Newbie Poster
17 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

try to direct output to a logfile, let's see what the error is

DimaYasny
Posting Virtuoso
Moderator
1,777 posts since Jan 2007
Reputation Points: 183
Solved Threads: 89
 

its working.thanks DimaYasny & eggi

wiz83
Newbie Poster
17 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

well, share the solution :)

DimaYasny
Posting Virtuoso
Moderator
1,777 posts since Jan 2007
Reputation Points: 183
Solved Threads: 89
 

10 07 23 1 * /usr/local/bin/perl /tpf106/data2/cis_web/cis3/cis3.11/work/rishi/s-branch/perl1/perl/filecomp.pl

the key was this part /usr/local/bin/perl.

wiz83
Newbie Poster
17 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

thanks, it's good to know, since I'm switching some of my scripting to perl in a few weeks

cron does run in a different nevironment then the usual shell

DimaYasny
Posting Virtuoso
Moderator
1,777 posts since Jan 2007
Reputation Points: 183
Solved Threads: 89
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You