Having trouble setting an environment variable with a cron job
Linux - NewbieThis 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!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Having trouble setting an environment variable with a cron job
I'd like to add a couple of environment variables to crontab (either the system crontab or my user crontab) called $TODAY and $TOMORROW. But when I add a line like this in my crontab:
well,
when you run a script from BASH what it does is run another "instance" (parallel shell) of Bash for the user which is running it
and thus it doesn't use the same Vars = it doesn't update what you want.
What is practice in scripting is to define a variable like:
'export' only exports vars/vals to any sub-shells called from the current shell they were defined in.
I think you are doing something odd here...
What exactly are you trying to achieve and why; this will help give a better answer.
Here's a little more explanation about what I am doing.
I have a headless server running Ubuntu 10.04.4 LTS that I access via ssh from several different machines. I know I could put the variables that I wish to define in $HOME/.profile or $HOME/.bashrc, but I also use GNU screen, so 99% I'm attaching and detaching the same session day after day. That means (because I'm not launching a new bash session), the definitions in .profile or wherever are evaluated once: when I log on at the beginning of a new screen session. Then they get "stale" because time marches on, but screen is still stuck with the environment it was initialized with.
FWIW, these variables are just little shortcuts for $TODAY and $TOMORROW that save me having to type out `date -d today|tomorrow +%F` every time I need the date (which is often).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.