Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-06-2012, 03:16 AM   #1
LQ Newbie
Registered: Mar 2012
Posts: 16

Rep: Reputation: 0

Why cron needs PATH variables should be set explicitly in it ??
when I scheduled a shell script through cron, the result was different comared to running the same script through console. Then I googled a lot and i found that PATH variables should be explicitly defined in cron and it worked, my script executed correctly. I dont understand why this should be done. Please explain me....
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-06-2012, 03:29 AM   #2
Senior Member
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,665

Rep: Reputation: 486Reputation: 486Reputation: 486Reputation: 486Reputation: 486
Probably your script assigned to cron for execution called for universal paths from the root stand point?
Old 04-06-2012, 03:42 AM   #3
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
We can only speculate why the designers or cron (in both its Vixie a.k.a ISC cron or Dillon a.k.a. dcron versions) decided to restrict the PATH value the way they did. It may have been for security.

Changing the default value of PATH in the crontab(s) is one way around that. A better way is for each script to set the PATH (and any other shell/process configurations: umask, limits, locale ...) it requires. That is good defensive programming practice; it makes scripts robust.
2 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
About crontab cola Slackware 2 12-29-2009 06:00 AM
linux crontab vs unix crontab ytd Linux - General 2 08-09-2009 05:07 AM
replaced crontab, now should get crontab back to what it was raminn Linux - Newbie 2 10-20-2008 07:15 PM
man crontab(5) vs crontab(1) Canis Polaris Linux - Newbie 2 06-04-2008 04:03 PM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration