cronjob to run perl script

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cronjob to run perl script
# 1  
Old 08-07-2008
Question cronjob to run perl script

Hi all
Recently i had finished a perl script. When i run manually, the script work fine.
But when i wanted to put the script in cron, it didn't get the same output as it run manually. I felt that it only execute the script until certain line then it stop as i see most of the related files didn't update after the script run by cron. Below is the cron i put

0,30 * * * * perl /home01/user/cheah/trigger_resend/ >/dev/null 2>&1

Did anyone can help on this?
Thanks very much...........
# 2  
Old 08-07-2008
0,30 * * * * perl /home01/user/cheah/trigger_resend/ >/dev/null 2>&1
- Did u try to use absolute path pf perl binary like, "/usr/bin/perl".
- Remember all your standard output/error you are redirecting to null.
by the wat what output should you expect ? where do you expect it?

- nilesh
# 3  
Old 08-07-2008
i havent try the absolute path.
What do you mean by "Remember all your standard output/error you are redirecting to null"
The output i meant is that i expected the script will generate 5 files after it being execute. But when using cron, it only generate one of the file, feel like the script processing half way
# 4  
Old 08-07-2008
Did you find anything in cron log ?
I assume your script has executable permissions. I tried following simple code in my host,

for i in 1 2 3 4 5
	touch file_$i
	echo "File generated : file_$i"

with these crontab settings,

10 21 * * * /root/ > /dev/null 2>&1
This is working for me....

- nilesh
# 5  
Old 08-07-2008
When you execute from your account there is an ENVIRONMENT. When you execute from cron there is no built-in environment and if you need anything like paths, etc. you have to specify it in your script, e.g.

$ENV{PATH} = "/x/y/z"; or what ever...

my $list_var;
open(HNDL, ">/some/simple/file.txt");
foreach $list_var ( sort keys %ENV )
print HNDL "$list_var -- $ENV{$list_var}\n";
close HNDL;

Try that from both your command line and from cron and see what the difference is in your environments. When you run from cron you might be missing something you will need to specify...
# 6  
Old 08-07-2008
take out the stdout a<nd stderr rediction, wait until it runs, and read the mail for the user in which you are executing that
(you need a mta)
# 7  
Old 08-08-2008
Hi Airwalker83,
If you haven't tried, you may put this as the first line of your perl script:
#!/usr/bin/env perl

and edit your crontab as:
0,30 * * * * /home01/user/cheah/trigger_resend/ >/dev/null 2>&1

assuming your script is executable.
If this doesn't solve your problem, you may try to put the following line as the first line of your script :
. /home/(username)/.bash_profile
to set the necessary environment in the script because of the reasons "quine" mentioned and leaving the crontab as your original post.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Run cronjob for every 10 minutes

Hi Friends, I have a requirement to run the cronjob for every 10 minutes from 2:00 AM to 6:00 AM. Does the below code works? If not, please advise. * * * * * command to be executed ┬ ┬ ┬ ┬ ┬ │ │ │ │ │ │ │ │ │ │ │ │ │ │ └---------------------------------- day of week (0 - 6) (0 is... (5 Replies)
Discussion started by: srikanthbiradar
5 Replies

3. UNIX for Dummies Questions & Answers

Script does not run from a user specific cronjob.

Hello, I have two crontabs, one for the root and one for another user. There is a script in my configurations that has to send a email. The script works and sends the emails when I run it by hand with either the root or the user, and when I program it in the root's crontab. But! It does not... (3 Replies)
Discussion started by: Tralaraloro
3 Replies

4. Shell Programming and Scripting

Schedule and Run By weekly shell script in cronjob

Hi All, How to schedule a shell script(script name- it should run by weekly in corn job or is there any script have to write to check week and then run the above script. example-1st run March 06 2013 2nd run March 20 2013 3rd run April 3 2013... (13 Replies)
Discussion started by: krupasindhu18
13 Replies

5. AIX

My script didn't run every run every minute at cronjob

In my cronjob, I would like to schedule my to run every minutes. I crontab -e and have in line below but it didn't seems to run at all. * * * * * When I run it manually, I can run it. Is that anything wrong with the above line? If I change it to something like below,... (4 Replies)
Discussion started by: ngaisteve1
4 Replies

6. Shell Programming and Scripting

Problems in running a Perl script via cronjob

I have a very basic perl script that attempts to find if a process is running. If the process is not running then the script is supposed to start the process. If I execute the script from command line it works fine as expected. However if the script is executed via cronjob, the script cannot find... (1 Reply)
Discussion started by: ypant
1 Replies

7. Shell Programming and Scripting

Running script that sends an html formatted email fails when its run as cronjob

Hi Im very new at working with unix and this problem I simply can not understand. I know there are a lot of threads about problems with shell scripts behaving differently when run from a terminal and from a cronjob. I have tried everything(almost) but I still havent cracked this problem. Im... (15 Replies)
Discussion started by: Nightowl
15 Replies

8. Solaris

How to run a script as different user inside cronjob in solaris.

Hi , I have a shell script to perform some actions on sun solaris box . This script normally requires to be run as a different user. so, whenever i have to run this script, i need to sudo in as that user , enter the password and execute it. Now,I have to setup a cronjob to execute the script... (11 Replies)
Discussion started by: csg_user
11 Replies

9. Shell Programming and Scripting

Perl: Run perl script in the current process

I have a question regarding running perl in the current process. I shall demonstrate with an example. Look at this. sh-2.05b$ pwd /tmp sh-2.05b$ cat #! /bin/sh cd /etc sh-2.05b$ ./ sh-2.05b$ pwd /tmp sh-2.05b$ . ./ sh-2.05b$ pwd /etc sh-2.05b$ So... (10 Replies)
Discussion started by: vino
10 Replies

10. UNIX for Advanced & Expert Users

cannot run cronjob

I have the following cron: 0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /v/sysadmin/sysnet/ The .pl has been tried at 755 and 777 The script works if manually run by the web browser or unix command prompt, but I can't get the Cron to do it automatically i went... (3 Replies)
Discussion started by: shahrahulb
3 Replies
Login or Register to Ask a Question

Featured Tech Videos