crontab and perl


 
Thread Tools Search this Thread
Operating Systems Linux crontab and perl
# 1  
Old 02-11-2010
crontab and perl

Hi ,
I don't understanding why my perl script is not executing through crontab .
but it runs properly if we run it at command prompt by typing "perl $path_of_script".
I found that cron daemon reads the line "perl $path_of_script" as command at proper timing defined in crontab and logs it in /var/log/cron.
But it is not executing.
I think it may be issue of environmental variables for cron daemon.
How to debug this issue ?
Thanks for help in advance.
# 2  
Old 02-11-2010
Export the .profile..

Ex:

Code:
30 * * * * (/home/user1/.profile ; perl /path/of/perlscript.pl)

# 3  
Old 02-11-2010
Hi,
I just check with above suggestion but it is not working.
I else tried with include

Code:
20 * * * * "source /home/user1/.bash_profile;perl $perl_script_path"

it is also not working
Then I write temp.sh file as

Code:
#/bin/bash
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
PATH=$PATH:$HOME/bin
export PATH

perl path_of_perl_file.pl

in one shell script and include it in crontab as
Code:
20 * * * *  /home/user1/temp.sh


but also not working .
can any body stress out !

Last edited by pludi; 02-11-2010 at 04:53 AM.. Reason: code tags, please...
# 4  
Old 02-11-2010
Quote:
Originally Posted by sandeepvson
Hi,
I just check with above suggestion but it is not working.
I else tried with include

Code:
20 * * * * "source /home/user1/.bash_profile;perl $perl_script_path"

it is also not working
That will never work since if you type "source /home/user1/.bash_profile;perl $perl_script_path" into a shell surrounded in quotes like that it won't work. It's the same syntax.

Try calling perl with an absolute path.
# 5  
Old 02-12-2010
I put line in my crontab as

Code:
50 09 * * *  (/root/.bash_profile;/usr/bin/perl /home/perl/env.pl)

Code:
& /var/log/cron    log file is as

Feb 12 09:50:01 localhost crond[6192]: (root) RELOAD (cron/root)
Feb 12 09:50:01 localhost CROND[26275]: (root) CMD (/root/.bash_profile;/usr/bin/perl /home/perl/env.pl)

It is reading declaration but not able to execute with cron daemon.

And my script is
============
Code:
#!/usr/bin/perl
## file env.pl

use strict;
use Env;

`echo -e "My home is $HOME\n" > LOG`;
`echo -e "My path is $PATH\n"  >>LOG`;
`echo -e "My username is $USER\n" >>LOG`;

============
it runs manually but not with cron daemon.

Last edited by pludi; 02-12-2010 at 02:52 AM.. Reason: code tags, please...
# 6  
Old 02-17-2010
You should "Shebang" perl

start the script (This must be at the first line of the script)
#!/<Path><To><Perl>

So it should look like this:


#!/usr/bin/perl

on most machines
# 7  
Old 02-18-2010
Solution for this

When we run a perl program from the crontab we can not access the perl modules.So inside the perl program we have to specify the modules in lib.

For example,
consider my module is in the directory /home/user/perlmodules.

So inside the program we need to specify like the following,

use lib /home/karthigayan/perlmodules
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. UNIX for Advanced & Expert Users

perl and HP-UX : instmodsh in combination with software depot : update inventory for installed Perl

we create a HP-UX software depot with a new perl-modul. after installation of the software depot, the perl module i can't find with instmodsh in the inventory for installed Perl modules. - i have learned of using instmodsh command : i find out what modules are already installed on my system. ... (0 Replies)
Discussion started by: bora99
0 Replies

3. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

4. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense. ... (4 Replies)
Discussion started by: kittyluva2
4 Replies

5. Shell Programming and Scripting

Problem with perl script on crontab

Hi everybody, I have a perl script. I want to run it as a cron job every 10 minutes. I insert the command into crontab , using crontab -e. The problem is, I didnt get any output from script inside crontab, whereas when I run it manually through 'perl myscript.pl' it running well. Here is the cron... (2 Replies)
Discussion started by: franzramadhan
2 Replies

6. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

7. UNIX for Dummies Questions & Answers

perl crontab entry not working

Hi I have a perl script which used 'glance' command to return all the processes with the thread count. It is working fine when it is executed as a command, but as a crontab entry, the perl script is not getting executed. thdcnt.pl #!/usr/bin/perl my $cmd=`glance -bootup -adviser_only... (1 Reply)
Discussion started by: manaac
1 Replies

8. Shell Programming and Scripting

Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl

Hi , This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated. use Time::Local; my $d = $ARGV; my $t = $ARGV; my $m = ""; @d = split /\//, $d; @t = split /:/, $t; if ( $d eq "Jan" ) { $m = 0 }... (7 Replies)
Discussion started by: akil
7 Replies

9. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

10. Shell Programming and Scripting

Run perl file in Crontab error.

Hi. I can run the script okay when I log in with root. Then I add this script to crontab and when crontab run i got this message error. I has installed DBD for Oracle already. I set ORACLE_HOME, ORACLE_BASE to root profile already. Please help me to fix it. It urgent. Thank so much. ... (2 Replies)
Discussion started by: raccsdl
2 Replies
Login or Register to Ask a Question