Operating System - HP-UX
1833903 Members
1936 Online
110063 Solutions
New Discussion

Simultaneuse variable definition confict ..

 
SOLVED
Go to solution
Vlad_11
Frequent Advisor

Simultaneuse variable definition confict ..

Greetings !
I have 2 mirror scripts, that run exactly at same time set thru cron.
shell #1 has:
PROC=billmag01
.....

shell #2 has:
PROC=bilmal77
...

eventually second script definition overides the first one (as their name are SAME=PROC), though I thought that those Vars will be accessible only inside their scripts.
I'm not doing iny special in my shells regarding Vars definition (exprot,etc...).

Is there any way to isolate those vars inside shells. Or probaly I can add any dinamic extensions to their names:
PROC.&&=billmag01 ....etc..

Will apprec any pro opinions, I have 25 of those shells, so thinking how to make it most reliable and fast.

Thank
Dai
beer or not beer
7 REPLIES 7
Vlad_11
Frequent Advisor

Re: Simultaneuse variable definition confict ..

Just clarification:
shell #1 has:
PROC=billmag01
.....

shell #2 has:
PROC=bilmal77
...

During execution shell #1 set PROC to bilma177 (that is from shell #2).

Tx
beer or not beer
David Burgess
Esteemed Contributor
Solution

Re: Simultaneuse variable definition confict ..

The variable definitions are isolated in the scripts. For example if one has a=1 and the other has a=2 each script will have a different value of a.

Regards,

Dave.
Michael Schulte zur Sur
Honored Contributor

Re: Simultaneuse variable definition confict ..

Hi,

if those scripts do not interact, it does not matter how often you use PROC, it is separated. More likely you have an unwanted assigment to PROC or a call . shell2

no need for PROC.&&

Michael
A. Clay Stephenson
Acclaimed Contributor

Re: Simultaneuse variable definition confict ..

Unless these two scripts are related as parent and child then the two have absolutely nothing to do with each other. They could, of course, inherit exported variabes from a common process but even in that case the two child processes cannot interact in the way you describe.

It is considered good form these days to use the typeset command everywhere.

#!/usr/bin/sh

myfunc()
{
typeset -i10 MYVAR=10
((MYVAR += 1))
echo "MYVAR inside myfunc = ${MYVAR}"
return 0
}

typeset -i10 MYVAR=100
echo "MYVAR = ${MYVAR}"
myfunc
echo "MYVAR = ${MYVAR}"

This example uses the same variable within
the same script. The typeset command used within a function causes the local copy to take precedence. The -i10 declares the variable to be a base-10 integer.


A typeset -x MYVAR command causes MYVAR to be automatically exported to child processes.
Man sh-posix for details.

One other way that two scripts can APPEAR to share data is the use of the "." command.

Inside shell1.sh if you add this statement:
. ./shell2.sh
then everything in shell2.sh becomes part of shell1.sh. It is NOT a child process, in that case.
If it ain't broke, I can fix that.
Vlad_11
Frequent Advisor

Re: Simultaneuse variable definition confict ..

Thanks, everyone !
Yes, theory is all right!
Probably I will expand my case, how it happened.
1.Each of shells send email, given value of PROC=bill is going to subject line, like:
elm -s " $PROC" -a $MAILTO < temp2 >> $LOGFIL

2. shell#1, shell#2 reside in same directory, but there is no any kind of interaction between them, neither misspelling in PROC=... definition.

3. I have mail sent by shell#1 (judge by logfile, email body and attachments) with subject from shell#2.

I realize that me is the main suspect in this case, but I checked multiple times all spelling in both shells.
Maybe ELM that uses SENDMAIL on background treats those variable somehow else then in shell or ....????


Thanks
Dai

beer or not beer
Vlad_11
Frequent Advisor

Re: Simultaneuse variable definition confict ..

+ more info:
both shells scheduled to run in cron:
00 21 2-5 * * /appl/shell1
00 21 3-6 * * /appl/shell2
beer or not beer
Steven E. Protter
Exalted Contributor

Re: Simultaneuse variable definition confict ..

When you use elm the mail transport agent is sendmail.

I agree with the conclusions above.

Just thought I'd confirm your thoughs on sendmail and elm.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com