Does 2 scripts running at same use a variable with same name conflict?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Does 2 scripts running at same use a variable with same name conflict?
# 1  
Old 11-30-2010
Does 2 scripts running at same use a variable with same name conflict?

All,
I have a Bash SFTP script that I run and before I would hardcode the file name.

I recently decided to put the filename in a variable called $FILENAME.

I had 2 scripts that run at the same time and it seems like in the middle of one of the scripts the variable called the other scripts $FILENAME for my put command.

So, my question is, aren't the variables in a script supposed to be local to the script? At the beginning of the script the variable was fine, but then the put command put the wrong file. See below, the variable $FILENAME switched from CQ12345 to CT12345 in the middle of the script. The other script I run at the same time's variable in CT12345

Script they both run except the FILENAME variable is different:
Code:
FILENAME=CQ12345
ARCHLOC=
LOGFILE=
GETDATE=`date`


#    echo start date to log

echo "Started script at $GETDATE" >> $LOGFILE

if [ "$(find $ORIGLOC/$FILENAME -type f)" ]; then

#    List files out to log

echo " The following file was found and is about to be transferred..." >> $LOGFILE

ls -l $ORIGLOC/$FILENAME >> $LOGFILE

#    Copy files to archive location

cp -pv $ORIGLOC/$FILENAME $ARCHLOC >> $LOGFILE

#    Copy files to new location

cd $ORIGLOC
echo cd INBOUND > /tmp/sftp.sftp
echo put $FILENAME >> /tmp/sftp.sftp
echo bye >> /tmp/sftp.sftp
sftp -b /tmp/sftp.sftp $DESTUSER@$DESTSERV >> $LOGFILE

Log
Code:
 The following file was found and is about to be transferred...
-rwx------ 1 root root 103675 Nov 26 11:56 /CQ12345
`CQ12345' -> `CQ12345'
sftp> cd INBOUND
sftp> put CT12345
Uploading CT12345 to /INBOUND/CT12345
sftp> bye


Last edited by markdjones82; 11-30-2010 at 01:13 PM.. Reason: Edited post to make it make more sense
# 2  
Old 11-30-2010
Do you have glob turned off? Are the filenames on disk really CQ******?

Normal syntax would be
Code:
FILENAME=CQ*

to find files starting with "CQ"

or CQ?????? to find a file starting with CQ that has any six characters after CQ
# 3  
Old 12-01-2010
Quote:
Originally Posted by jim mcnamara
Do you have glob turned off? Are the filenames on disk really CQ******?

Normal syntax would be
Code:
FILENAME=CQ*

to find files starting with "CQ"

or CQ?????? to find a file starting with CQ that has any six characters after CQ
Jim, sorry I shouldn't have used **** I was just using that as a comment out for the rest of the characters of the file name. It is something like CQ12345 and the other file is CT12345. My SFTP scripts pull these files from the same directory, but both are separate scripts. One has filename set to CQ12345 and the other CT12345. They execute on the same cron schedule.

If you look at the log, it finds the CQ file, but then when it ran the put command it used the CT file name instead of the CQ file name. Maybe I had it hardcoded still at that portion instead of the $FILENAME as I copied it from my original script and then edited? Could be programmer error, but i'm pretty sure I had $FILENAME right after the put command when I looked it. I know for sure it has it now. Smilie

I'm not sure how to check if glob is turned off/on. It is running RHEL 5.5 so whatever the default for that is.

I just wanted to be sure that the variable should stay local to that script. That assumption should be correct right? I can run some tests with echo when I get back in office.

---------- Post updated 12-01-10 at 10:43 AM ---------- Previous update was 11-30-10 at 01:08 PM ----------

Quote:
Originally Posted by jim mcnamara
Do you have glob turned off? Are the filenames on disk really CQ******?

Normal syntax would be
Code:
FILENAME=CQ*

to find files starting with "CQ"

or CQ?????? to find a file starting with CQ that has any six characters after CQ
I just realized the problem. The temp file I wrote the SFTP commands to that the sftp -b would read from had the same name. So, when they executed at the same time. It overwrote it with the other file names.

Programmer error!

Last edited by markdjones82; 11-30-2010 at 01:19 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Running scripts from different server

Hi, I need a script (ksh) on ServerAdmin that will run an archive scripts from different several Servers through ssh. The problem is that how can i switch user when before running the archive script. I already configured password-less connection on the servers. server 1... (1 Reply)
Discussion started by: chococrunch6
1 Replies

2. Shell Programming and Scripting

Change Variable Value from Multiple Scripts and Use these Variable

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)
Discussion started by: div_Neev
2 Replies

3. Solaris

running scripts from cron

I need to run a script (from cron) that runs a second script. What worries me is that second script, when run from bash, upon finishing doesn't return to bash unless I press the 'Enter' key. I presume that's because last command in that script ends with & Could that be a problem for cron?... (2 Replies)
Discussion started by: orange47
2 Replies

4. Shell Programming and Scripting

running scripts in minicom

Hi, I am new to use minicom. I want script to run on minicom with username and password as automated.(Expect). please could anyone suggest the sample code for it. Thanks in advance (2 Replies)
Discussion started by: vanid
2 Replies

5. Shell Programming and Scripting

Running 2 scripts one after the other using cron

I would like to run two scripts using cron one immediately after the other. Is it enough to put them one after another in the cron file to run at the same time, or will this cause them to run concurrently? (4 Replies)
Discussion started by: 3210
4 Replies

6. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

7. Shell Programming and Scripting

sequential running for 2 scripts

Hello I have a script that has 2 scripts that must be executed one after the other. however, when I run the script, the 2 sub-scripts are run in parallel. any idea how to fix this without using sleep command? thank you (7 Replies)
Discussion started by: melanie_pfefer
7 Replies

8. Shell Programming and Scripting

Running scripts via su

Hi All, Am using the below command to start my application using the root user su - bin -c "/home/bin/test/start.sh" but am getting the error becaue i have set some environment varibales in bin .profile when i execute the command start.sh by logging directly into bin account it's... (8 Replies)
Discussion started by: ravi.sri24
8 Replies

9. Shell Programming and Scripting

Running scripts through cronjob.

Hello everybody, I'm trying to run a shell script in crontab file. But anyhow it's not getting executed. Following is the command that I've used in crontab. 30 07 * * * . ./.cronprofile;/om/reports/reportscripts/jitu/prod/prd_pre_to_post.sh 35 11 * * * .... (3 Replies)
Discussion started by: jitu.jk
3 Replies

10. UNIX for Dummies Questions & Answers

Running scripts from home

I have created a Bourne shell script that helps with metric counting and it has to be run in a ClearCase view. It has been placed in a directory where if User A cd'd to it and runs it, a bunch of errors occur. Because this is a tool that several users would want access to and the program assumes... (2 Replies)
Discussion started by: mastachef
2 Replies
Login or Register to Ask a Question