Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 04-25-2009, 07:37 PM   #1
LQ Newbie
Registered: Apr 2009
Posts: 28

Rep: Reputation: 15
how to set global environment variables?


I am setting PATH=$PATH:/demia on /etc/profile

it is supposed to set it globally but cronjobs are unaware of those newly set variables. Only root (without su) is aware of it.

i would like to set this once from a script at boot time and i want every user, every su command, every cronjob to access it without further ado.

Any ideas?

Old 04-25-2009, 07:55 PM   #2
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 88
Does your system have an /etc/environment file? Have you tried setting it in there?
Old 04-26-2009, 01:00 AM   #3
LQ Newbie
Registered: Apr 2009
Posts: 28

Original Poster
Rep: Reputation: 15
I just set them there, but nothing happened.
$ env
doesnot show any variable that resides in the file you mentioned.


snippet from /etc/environment
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ami_tools/bin";
export JAVA_HOME="/usr";
export EC2_HOME="/home/ami_tools";
Old 04-26-2009, 01:00 AM   #4
LQ Newbie
Registered: Apr 2009
Posts: 28

Original Poster
Rep: Reputation: 15
I did reboot after. To be sure.
Old 04-28-2009, 10:10 PM   #5
LQ Newbie
Registered: Apr 2009
Posts: 28

Original Poster
Rep: Reputation: 15
I found out that environment file is not shell so for others, quick note:
format is below: it works this way.

Old 04-29-2009, 11:33 AM   #6
Registered: Mar 2007
Posts: 100

Rep: Reputation: 17
crontab has its own PATH settings. You have to edit the PATH setting there in /etc/crontab file

$ cat /etc/crontab

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

or if you are doing crontab -e, then you can manually add "PATH=<your paths>" at the top.

Old 04-29-2009, 12:29 PM   #7
Senior Member
Registered: Sep 2003
Posts: 1,091

Rep: Reputation: 41
/etc/profile.local in Suse. I generally call my scripts in cron with, su -c which will load the appropriate localized user environment variables.

Last edited by trey85stang; 04-29-2009 at 12:30 PM.


env, environment variable

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
global environment variables in shell script a.toraby Programming 2 11-11-2007 04:25 AM
set environment variables johnvdster Linux - Newbie 2 05-30-2006 06:15 AM
how do i set environment variables? guitarfella Slackware 2 12-05-2004 12:05 AM
How to set environment variables anjaan Linux - General 3 06-10-2004 03:04 PM
Help with the currently set environment variables!! apoc013 Linux - Newbie 6 01-21-2004 02:28 AM

All times are GMT -5. The time now is 07:28 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