![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 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. |
|
||||
|
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. |
|
||||
|
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. |
|
||||
|
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? |
|
||||
|
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? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|