LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-06-2003, 06:01 AM   #1
davee
Member
 
Registered: Oct 2002
Location: Ayrshire, Scotland
Distribution: Suse(home) RHEL (Work)
Posts: 263

Rep: Reputation: 30
Setting global variables from a crontab job


I've a simple test script:

#!/bin/bash

case $SET_THIS in
one) export SET_THIS=two
;;
two) export SET_THIS=three
;;
three) export SET_THIS=one
;;
*) export SET_THIS=one
;;
esac
echo $SET_THIS

It sets the $SET_THIS variable in the current shell if I run it will a '.' ie . ./setscript - but - how do I do this from running the command from a crontab job? Is it possibe? I would like the crontab job to know the previous value of the variable when the script starts...

Dave

Last edited by davee; 10-06-2003 at 06:03 AM.
 
Old 10-06-2003, 07:10 AM   #2
stv_t
Member
 
Registered: Oct 2003
Location: Gatwick, UK
Distribution: Mandrake 9.1, Mandrake 9.2, Redhat 9.0
Posts: 47

Rep: Reputation: 15
Hi Davee

This depends on how the variable is set, from an interactive shell session or a previous running of the crontab script.
1 Set by an interactive shell
I think that the way to do this is to create a logout script that edits your bash/ksh rc file to reflect the current value of the variable or if the variable needs to be the same each time you log in then create a separate file that contains the value and then place '. var_file' at the start of the crontab script ie
.bash_logout contains
echo "export SET_THIS=$SET_THIS" > ~/.cron_set

.bashrc contains
. ~/.cron_set - to set SET_THIS on each shell invocation
or
crontab script contains
. ~/.cron_set - To only set SET_THIS when run from crontab

2 Set by previous crontab script
Simply add .
~/.cron_set - to the start of the crontab script
and
echo "export SET_THIS=$SET_THIS" > ~/.cron_set - to the end of the script.

Don't forget to give an initial value in ./.cron_set
 
Old 10-06-2003, 08:05 AM   #3
davee
Member
 
Registered: Oct 2002
Location: Ayrshire, Scotland
Distribution: Suse(home) RHEL (Work)
Posts: 263

Original Poster
Rep: Reputation: 30
Thanks for that! I'll give it a try and see what happens. It's one of these things that doesn't seem to be covered in any of my linux books.

Cheers, Dave
 
  


Reply


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
g++ complains about global variables copolii Programming 3 09-18-2005 09:43 PM
Local vs Global variables wujee Programming 1 03-12-2005 12:43 AM
Setting global system variables AzidStar Linux - Newbie 5 03-11-2005 10:03 AM
global variables in php champ Programming 2 10-13-2002 02:31 PM
exporting global variables neo77777 Programming 6 09-18-2002 02:46 PM


All times are GMT -5. The time now is 09:34 PM.

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