LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-20-2012, 05:07 PM   #1
rs232
Member
 
Registered: Oct 2005
Posts: 43

Rep: Reputation: 0
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
 
Old 07-20-2012, 05:32 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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.
 
Old 07-20-2012, 06:15 PM   #3
rs232
Member
 
Registered: Oct 2005
Posts: 43

Original Poster
Rep: Reputation: 0
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.
 
Old 07-22-2012, 10:25 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
cron jobs run in their own detached env.
They do not communicate with eg a login shell.
 
Old 07-23-2012, 05:00 AM   #5
rs232
Member
 
Registered: Oct 2005
Posts: 43

Original Poster
Rep: Reputation: 0
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
 
  


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
my database export shell script run from command line but not form crontab saifee Linux - General 11 01-29-2012 10:24 AM
How do I make a script to export its variables to the invoking shell? stf92 Linux - Newbie 7 10-06-2011 08:25 AM
How can I export my variables from a script? HGeneAnthony Debian 2 05-20-2006 05:47 PM
Unable to export variables declared in a script joehansen12 Linux - Newbie 2 10-26-2005 03:25 PM
why do we have to export variables? learnfast Linux - Newbie 2 05-27-2005 09:27 AM


All times are GMT -5. The time now is 03:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration