LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Export variables within the script. How to crontab it? (https://www.linuxquestions.org/questions/linux-newbie-8/export-variables-within-the-script-how-to-crontab-it-4175417860/)

rs232 07-20-2012 05:07 PM

Export variables within the script. How to crontab it?
 
Hi all, I'm writing my /bin/sh script that messes around with variables. Eventually I got to the point an need to export the variables.

Code:

export varialbe1=10
export variable2=95


calling from sh:

Code:

. ./variables.sh
Code:

echo variable1: $variable1
echo variable2: $variable2

does the job, but how can I add this to the contable? I mean let's say that this script is saved into /usr/local/bin/variables.sh
How do I add an entry to the contable that achieves exactly what

Code:

. /usr/local/bin/variables.sh
does?

Thanks

Kustom42 07-20-2012 05:32 PM

You can simply put that code into your crontab or you can use the "source" command and reference the file or even simpler you can export your variables within the crontab itself.

---------- Post added 07-20-12 at 02:33 PM ----------

Also, /bin/sh is just a symlink to your current shell. Best practices are to path to the actual shell you want it to run under, /bin/bash or /bin/ksh for example.

rs232 07-20-2012 06:15 PM

I've tried to just run the command from the crontable (without the dot in front), it doesn't seem to be working as the variables defined and exported within the script are not visible to e.g. an echo on the shell.

I don't have the source command either. I should have mentioned that I'm running this on a linux router running busybox. sh is the only option I have right now.

chrism01 07-22-2012 10:25 PM

cron jobs run in their own detached env.
They do not communicate with eg a login shell.

rs232 07-23-2012 05:00 AM

As this runs on a router I "could" save on nvram but I know very well that this doesn't scale and also could damage the nvram if heavily used.
I ended up writing variables in a file, using a simple echo to inizialize the file and sed to replace values. In any case the linux filesystem in a router is entirely stored in RAM so it does the same and appears to be working fine.

Thanks any ways


All times are GMT -5. The time now is 05:39 AM.