LinuxQuestions.org
Help answer threads with 0 replies.
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, 04:07 PM   #1
rs232
Member
 
Registered: Oct 2005
Posts: 51

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, 04:32 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
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, 05:15 PM   #3
rs232
Member
 
Registered: Oct 2005
Posts: 51

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, 09:25 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,389

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

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 09:24 AM
How do I make a script to export its variables to the invoking shell? stf92 Linux - Newbie 7 10-06-2011 07:25 AM
How can I export my variables from a script? HGeneAnthony Debian 2 05-20-2006 04:47 PM
Unable to export variables declared in a script joehansen12 Linux - Newbie 2 10-26-2005 02:25 PM
why do we have to export variables? learnfast Linux - Newbie 2 05-27-2005 08:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:40 AM.

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
Open Source Consulting | Domain Registration