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 |
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 |
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 |
All times are GMT -5. The time now is 11:59 PM. |