Avoid locking between two files:

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Avoid locking between two files:
# 1  
Old 10-10-2013
Avoid locking between two files:

Hi frnz,

I have requirement as follows..

There are two Modules say A and B...n both have few set of files..we have one script which read these files and load into database(vertica) table..while running script smtimes i encounter an error like one table is getting loaded from A module file also and module B file also..and due to this licking my script fails.

Now A & B run parellely so when A's file getting loaded into table it locks the table and B files fails to load..

so i want to add a piece of code where my script will wait till A file completley load into table and stop the file of B..n once A file loaded it will start loading B file into B..

Overall i need to Develop table update dependency tracking to avoid query failure due to table lock.
I knw its very confusing but if anyone can provide some input , i wud be very grateful..

# 2  
Old 10-10-2013
Your scripts should use a flag to avoid conflict.

This flag should be created using an atomic operation (like mkdir or using clobber stuff).

Atomic means that if your both script tries to setup the flag at the same time, only one of them will pass and the second will fail.

But you will then have to check against the successful creation of the flag before your script run and erase the flag when it ends.

Last edited by ctsgnb; 10-10-2013 at 10:15 AM..
# 3  
Old 10-10-2013
well thanks for the idea..i wud be grateful if u can provide sm unix script for that or atleast sm kind of pseudo code...

Thanks again
# 4  
Old 10-10-2013
If you can tell us your OS, please.
# 5  
Old 10-10-2013
Why don't you use DB locking mechanisms? Sth like "select * from table for update"?
# 6  
Old 10-10-2013
@jim_mcnamara::--i am using Windows OS but connected to LINUX server to write n execute my shell scripts...so i guess i need a code corresponds to LINUX OS...

---------- Post updated at 07:02 AM ---------- Previous update was at 06:57 AM ----------

well i am using cron jobs to run my script.. i have one load_cdr script which loads all files in diff modules to table...actually i dont want to put lock on table rather i need something like if A module file and B module File are interdependent then my script should run first A file and wait till it completes and then B file should execute...

So as per my understanding if i put some lock while reading module A file and if B module File comes into the picture my script will go in sleep mode till the lock on Module A file gets remove...smthin like that..but i am not getting how to write this into unix script..

# 7  
Old 10-10-2013
The second script using select ... for update will automatically go to sleep.

If always script A runs first to completion, then script B, why don't you just run them sequentially?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

How to avoid errors when moving files in a bff?

I am building a bff using mkinstallp. My template file is : Package Name: svr_exForum Package VRMF: 7.2 Update: N Fileset Fileset Name: svr_exForum.rte Fileset VRMF: 7.2 USRLIBLPPFiles Pre-installation Script: /lppdir/lpp/exForum/F_pre_i ... (2 Replies)
Discussion started by: kevinl
2 Replies

2. Ubuntu

Avoid typing long filenames in terminal, shortcut for selecting files?

You probably know the answer to this, because I know it exists. I have super long filenames with md5 hashes and I sucks to type the whole hash in the console. Because... just because :P What is the shortcut for selecting a file in the current directory? Like you get a sort of loop through the... (1 Reply)
Discussion started by: hellfire1
1 Replies

3. Shell Programming and Scripting

Joining 3 AWK scripts to avoid use "temp" files

Hi everyone, Looking for a suggestion to improve the below script in which Ive been working. The thing is I have 3 separated AWK scripts that I need to apply over the inputfile, and for scripts (2) and (3) I have to use a "temp" file as their inputfile (inputfile_temp and inputfile_temp1... (2 Replies)
Discussion started by: cgkmal
2 Replies

4. UNIX for Advanced & Expert Users

Samba - prevent locking of selected files over network?

I have a samba server which is serving a mixture of files. One main application uses a data file and creates a temporary working execution file at startup and holds that temp execution file open for the duration of the program's execution (but doesn't use the file at all after initial startup). ... (0 Replies)
Discussion started by: humbletech99
0 Replies

5. Shell Programming and Scripting

How to avoid duplication within 2 files?

Hi all, Actually 2 files are there - file1, file2. file1 contains ---> london mosco america russia mosco file2 contains --> europe india japan mosco england london Question is I want to print all the city names without duplication cities in those... (10 Replies)
Discussion started by: balan_mca
10 Replies

6. Shell Programming and Scripting

How to Avoid intermediate files when pipe does nt work

problem with piping one output to another.Would like to avoid the intermediate file creation.The piping does nt work on places where files have been created and goes in an endless loop. sed -e "s/^\.\///g" $LINE1| sed -e "s/_\(\)/kkk\1/g" > $file1 tr -s '_' ' ' < $file1| \ sort -n -k... (1 Reply)
Discussion started by: w020637
1 Replies

7. Shell Programming and Scripting

Avoid files being archived

hi all, i want to write a shell script which can automatically touch my all files within a folder in an interval of 90 days ...so that i can avoid them being archived. I don't want to manually touch the all files instead i want an automated shell script to do this. Thanks in advance, Om (3 Replies)
Discussion started by: koti
3 Replies

8. Programming

What is the proper way to combine C++ files (with g++) to avoid link (ld) errors?

Problem background: gcc v 4.1 2 .cpp files, 2 .h files Files: main.cpp a.cpp a.h b.h Organization: main.cpp includes a.h (because it calls a.cpp code) a.cpp includes a.h a.h includes b.h (because a class in a.h uses a b.h class) There is no inheritance between a.h or b.h or any of... (1 Reply)
Discussion started by: johnqsmith
1 Replies

9. Ubuntu

Avoid creating temporary files on editing a file in Ubuntu

Hi, My ubuntu flavor always create temporary files having filename followed by ~ on editing. For eg: if I am editing a file called "sip.c", automatically a temporary (bkup) file is getting created with the name "sip.c~". How to avoid this file creation? (7 Replies)
Discussion started by: royalibrahim
7 Replies
Login or Register to Ask a Question

Featured Tech Videos