The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script through cron and command line rahulrathod UNIX for Dummies Questions & Answers 3 02-22-2008 07:10 AM
works step by step on command line but not in script whamchaxed Shell Programming and Scripting 2 12-06-2007 07:47 AM
works from cmd-line but not in script OFFSIHR Shell Programming and Scripting 4 10-18-2006 08:41 AM
Works Manually - not in CRON dstinsman UNIX for Dummies Questions & Answers 5 03-06-2006 08:36 AM
Adding command line env in cron env abhijeetkul Shell Programming and Scripting 1 12-13-2005 09:42 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-26-2007
JackTheTripper JackTheTripper is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 3
script works on command line, not in cron job

Hey there, I'm a total newbie unix guy here and just picking this stuff up. Have a very small script I put together that works fine from the command line but not once I put it in a cron job. Searched and found this thread and am wondering it it has something to do with setting variables, though the error I'm getting seems to be with exicuting the date() function.

Here it goes...
Code:
lastUpdate="`more /path/to/date/file/lastUpdated.txt`"; 
daDate="`date '+%Y %m %d'`"; 
if test "$lastUpdate" = "daDate"; 
then wget --output-document="/path/to/docs/$daDate - daFile.pdf" http://www.mysite.com/downloadMe.pdf"; 
fi
the 'lastUpdated' file contains a date like so... "2007 06 26"

Like I said, if I put this in the command line it works great, just not in a cron job.

Thanks in advance for the help.
  #2 (permalink)  
Old 06-26-2007
jgt jgt is offline
Registered User
  
 

Join Date: Apr 2007
Location: 44.21.48N 80.50.15W
Posts: 439
The environment variable PATH is different for cron jobs than for your shell.
Add 'env >/tmp/cronob.log' at the beginning of your script and find out exactly what the path is, then either modify it in the script, or use the absolute file name for the command.
  #3 (permalink)  
Old 06-26-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
As mentioned, normal reason for this is the environment (eg all the strings you see printed when you type "set") is minimal when run as a cronjob. This requires you to set any environment variables you will rely on directly in your script.

Also, you are missing the normal "#!/bin/sh" line from the start of your script, this tells the operating system which interpreter/shell to use to run your script.
  #4 (permalink)  
Old 06-26-2007
JackTheTripper JackTheTripper is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 3
Both, thanks for the reply.

I put env >/tmp/cronob.log into the script (as well as #!/bin/sh, thanks) and still doesn't seem to be working. I'm not sure what you mean by "you need to set any environment variables". Do you mean I need to do that in this log file?
  #5 (permalink)  
Old 06-26-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Jack,
You will understand better if you type the command 'env' in the unix prompt.
Your script may need some of these variables to run properly.
One solution is to add the following line into your script:
Code:
. ~/.profile
  #6 (permalink)  
Old 06-26-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Reading the FAQs prior to posting tends to be the most helpful.
  #7 (permalink)  
Old 06-26-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Some things that leap out at me are

1. Are you going to set the current directory to the one you expect for this script?

2. is wget on the PATH that your script gets, if not use a fully qualified path to wget

3. did you put the fully qualified path to your script in the crontab?

4. did you set the executable flag on your script?
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0