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 December 27th, 2004, 12:05 PM
dmuxaf dmuxaf is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Overseas - Azores
Posts: 7 dmuxaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 36 sec
Reputation Power: 0
Question Crontab

Hello. Bare with me, I am still learning UNIX. So, you may laugh at the simplicity of my questions.

I'd like to know a few things that I have not been able to find online. I may have just not found the right spot yet. But, a lot of my searching ends up in forums. So, I thought I might as well just start a thread.

I have been fooling around with crontab. It seems very simple according to the man pages; however, one of my entries will not work. I know I have the 5 entries for the duration the command is executed set correctly...and I know I haven't fat-fingered anything else. I see in the log file (/var/adm/cron/log) that an attempt is made to execute the command. I was told some of the characters on the line in the log could point to an answer. But, I am unable to decrpyt anything.

I have the entry set to run a script I built, which runs when I manually type it. Also, I have another entry in the crontab file - that works - to run another script I built. Each script is set to run at a different time, so I don't think there would be any conflicts. I am not sure why cron will not complete it.

Any advice is appreciated!

...now you can laugh

Reply With Quote
  #2  
Old December 27th, 2004, 03:56 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,430 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 21 h 41 m 55 sec
Reputation Power: 784
It's hard to pinpoint the problem without seeing the log. However, one of the things to bear in mind is that the cron jobs run under a different environment than your regular login. In particular, cron doesn't have the same PATH variable as your login, hence you should specify all pathnames as absolute path names, to be safe. This is the #1 cause of errors in cronjobs.

For example, if you wanted to print a list of files, you could simply type "ls" and get a list. This is because your PATH variable has "/bin" in it and so the shell can find it. With a cron job, you may need to type "/bin/ls" so that it can find the program.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month

Reply With Quote
  #3  
Old December 28th, 2004, 02:34 AM
dmuxaf dmuxaf is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Overseas - Azores
Posts: 7 dmuxaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 36 sec
Reputation Power: 0
Here is the line from crontab -l

30 * * * * /d2/www/offline_prob/g_offline

My script only has two commands and I am redirecting the output to another file. I'm still working with the script, so there will be more entries for it; however, I'd like to go ahead and use cron to automate it. BUT...problems...

I didn't know about the PATH variable and cron...thanks for the info.

Reply With Quote
  #4  
Old December 28th, 2004, 07:26 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,078 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 14 h 28 m 26 sec
Reputation Power: 9
as scorpion said, cron has a very limited ENVIRON, not only PATH but all other
variables set by the login-session are missed.
q1: witch shell are you using
q2: witch shell is cron using
you have different way to fix that:
- scorpion's suggestion: use full qualified names NOT only for cron but also
for the script running
penalty: you loose flexibility in the script.
- set the envs using 'env'
eg: * * * * * /bin/env XXX=xxx YYY=yyy /your-command
now cron (/your-command) knows the values of $XXX and $YYY
penalty: for each changes you have to reedit cronttab
- FORCE cron to process your $HOME/dotfiles
eg: * * * * * . $HOME/.profile ; /your-command
note the dot before dollar
- FORCE the script to process your $HOME/dotfiles (my preferred way)
eg: * * * * * /your-command (assumed you use /bin/sh)
and in /your-command is:
#!/bin/sh
. $HOME/.profile # again, note the dot at begin
..... the rest of code
no penalty, the code will run

ps: the only values known by cron are the entries in /etc/passwd for that user
and (like scorpion said) a minimal PATH, nevertheless i expect '/bin' in it.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Crontab


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