SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old July 2nd, 2004, 03:12 PM
yogi27 yogi27 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Dallas
Posts: 50 yogi27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Executing a script through a cron job

I have a script file that gives the correct output when manually run at the command prompt: perl nov.pl

But, when I schedule it in a cron job like: 0 15 * 7 5 perl /path/nov.pl, it does not execute.

The other cron jobs work fine and I have even added new cron jobs to execute different perl scripts, and everything works. I don't understand why this particular perl script does not execute when given in a cron job.

Can someone please help me out with this issue. Thank you.

Reply With Quote
  #2  
Old July 2nd, 2004, 03:28 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
If the first line of your script is a she-bang something like:
Code:
#!/usr/contrib/perl


You do not need the "perl" part of the cron command, which is likely what is causing your problem. cron doesn't necessarily have a PATH environment variable from the getgo.

Reply With Quote
  #3  
Old July 2nd, 2004, 03:30 PM
faulkner faulkner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 103 faulkner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
^^^^his idea is better.

Reply With Quote
  #4  
Old July 2nd, 2004, 03:48 PM
yogi27 yogi27 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Dallas
Posts: 50 yogi27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Jim,

I deleted the perl in the cron job command, but it still did not work. I have other cron jobs that specify perl in the command line and they work fine.

I have been on it for a day now and I don't see any problem with the perl file. There are Switch, if statements in the file, just for your info.

Please let me know what do you think might be the problem. Thank you.

Reply With Quote
  #5  
Old July 2nd, 2004, 08:02 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
Your environment (environment variables) are not set right,
or your code is failing because of file permissions. Assuming you tested the heck out of your perl code.

Put this script up for testing:
Code:
#!/bin/ksh
set > /tmp/cronpath.txt


1. Compare the envrionment variables in the cronpath.txt with a set command issued by you when you are testing the perl script.

2. If nothing turns up, it has to be permissions.
Code:
0 15 * 7 5 perl /path/nov.pl 2>/tmp/cronerrors.txt


See what you get in cronerrors.txt

Reply With Quote
  #6  
Old July 3rd, 2004, 04:29 AM
stevengs stevengs is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Germany
Posts: 394 stevengs User rank is Lance Corporal (50 - 100 Reputation Level)stevengs User rank is Lance Corporal (50 - 100 Reputation Level)stevengs User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 4 h 36 m 24 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
hey Jim,
that is an excellent idea. Right on time. So many people run into problems with cron that boil down to either the privileges or the environment of the cron user. Using set and diff helps make the situation plain as day. I'd almost go so far as to suggest making that last post "sticky".

-Steven

Reply With Quote
  #7  
Old July 6th, 2004, 01:47 PM
yogi27 yogi27 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Dallas
Posts: 50 yogi27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Jim,

The cronerrors.txt file gave me an error that the Switch functionality is not supported. So I changed the Switch statement to an if-elsif statement. Its working perfectly now. Thanks a lot for your help. Its a big relief.

-Yogesh.

Reply With Quote
  #8  
Old July 6th, 2004, 04:19 PM
yogi27 yogi27 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Dallas
Posts: 50 yogi27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Jim,

I still don't understand how did the script execute at the command line (perl nov.pl) but gave an error for the Switch statement when executed through the cron job.

-Yogesh.

Reply With Quote
  #9  
Old July 6th, 2004, 04:57 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
A guess -
try:
Code:
echo $SHLIB_PATH

This is the search path that dld (the dynamic loader) uses to find modules. perl uses dld to load shared libraries.

If you assume there are some different versions of perl (GNU vs something else) on your box, then changing or not having SHLIB_PATH or some entry in PATH would make you use different run time libraries. One RTL has switch - the other can't find it. libperl is the library.

You can do this to see what the cron job is doing - but you need TONS of disk space - find either tusc or strace on your system. I don't know where they live on your box, so I'm making up a path:
Code:
0 15 * 7 5  /usr/sbin/strace perl /path/nov.pl > /tmp/crontrace.txt


Then at the command line do:
Code:
/usr/sbin/strace perl /path/nov.pl > crontrace.txt


grep for the word "open" and look for shared library names -
in both logfiles. You may even be starting different versions of perl for all I know. Like /home/yogesh/perl vs /usr/local/contrib/bin/perl

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Executing a script through a cron job


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway