Using same variable in 2 different scripts that run at the same time
Hi,
I have two scripts that use the same variable. Say suppose I export that variable in script 1 and try to use it in script 2 where I have declared it locally, what will be the effective value of the variable? Will it take the exported value or the locally declared?
example:
Script1
ABC=$FILENAME
export ABC
Script2
ABC=XYZ.txt
echo $ABC --> what will be the output here
Given that you overwrite ABC before you print it in script 2, ABC will always end up "xyz.txt" in that script no matter what it was before. Their values aren't protected in any way. But that's beside the point...
Variables don't travel "sideways" like that. They don't actually travel at all -- each and every program has its own, independent set of exported variables, called the 'environment'.
When you run a script or program, it gets a copy of your current environment. But the copy is unconnected. Change the child and the parent remains the same, and vice versa.
If you wanted the same variable to be set in two different programs, either set it earlier in your ~/.profile or ~/.bashrc file so it gets exported on login for you, or have a little config file thing for your scripts to source:
The "." operator runs the given script inside the current shell. This is very different from just executing './littleconfigfile' because . allows you to set your own variables instead of setting variables in a useless copy.
Last edited by Corona688; 12-15-2011 at 02:50 PM..
I actually have multiple sctipts that use the same variables in them and they all use export function in each of these scripts. My doubt is that if I would run all these scripts parallely using a single cron, will they confuse with the value of this common variable or it doesnt matter at all?
My doubt is that if I would run all these scripts parallely using a single cron, will they confuse with the value of this common variable or it doesnt matter at all?
Thanks
Each process is its own private, independent universe. The value of 'VARIABLE' in some other process' memory doesn't matter to them one bit. All they start with is whatever values cron happens to have the instant it starts them -- which is, intentionally, almost a clean slate. And once they're started nothing from the outside affects them.
Last edited by Corona688; 12-15-2011 at 03:35 PM..
Could I run 2 python scripts at the same time side by side output on the same line in this same format but with scripts?
from itertools import izip_longest
with open("file1") as textfile1, open("file2") as textfile2:
for x, y in izip_longest(textfile1, textfile2, fillvalue=""):
x =... (4 Replies)
Assume I want to run a sequence of scripts:
script0001.sh
script0002.sh
script0003.sh
...
script0122.sh
script0123.sh
I only know a little Linux scripting, so the following is the best I can write
for k in $(seq 1 123)
do
./script${k}.sh
done
Of course it doesn't work... (2 Replies)
I am from MQ/MB technology. My requirement is to display the queue manger and broker status on daily basis.
If I manually run the script, it works fine and displays output. But when I have scheduled the same using cronjobs it shows only the queue manger status and not the broker status.
Can... (3 Replies)
Hi,
Below is starting entry of my script
#!/bin/ksh
Usage()
{
print "Usage: $0 ID OPTION SERVER"
print "<br>Where :"
print "<br>Enter your ID into PARAM1, OPTION in the PARAM2 and SERVER in the PARAM3 field"
print "<br>ID should be a valid ID"
print "<br>OPTION should be either... (2 Replies)
Hi to All,
Please find below details.
file_config.config
export file1_status="SUCCESS"
export file2_status="SUCCESS"
file_one.sh
I am calling another two shell script from these script. I need to pass individual two script status (If it's "FAILED") to file_main.sh.
file_main.sh
I... (2 Replies)
HI,
I have to write a unix script and need your help.
in my application where I have to invoke this script a varialble is there where the value comes in a variable . for example variable can be var=ABC
like this there will be any type of value in the vcariable.
there is a unix directory... (2 Replies)
I am going to run the scripts (filetest.sh)
Its run with.....
./filetest.sh
sh filetest.sh
but not run with.....
filetest.sh ( giviing error command not found)
tell me the way how we can do it ? (6 Replies)
hi,
I have one environment variable like path in my system.But in my program i need to change that path .suppose it has a value "config" now i need to chage it as "config1" or something else.i need to use that variable for complete project.It means at first it will use the old path but after... (4 Replies)
Hi !!
How do u run three scripts one after another automatically using crontab command at some specified regular interval.
Say i have three scripts A,B,C and i want to run the three scripts A followed by B followed by C.
REQUIRE HELP URGENTLY
Thanks in advance
Arunava
. (3 Replies)