I
I
Ivan Safonov2017-10-17 13:26:45
linux
Ivan Safonov, 2017-10-17 13:26:45

How to not rewrite variables when running a bash script at a time?

Good day.
Now there is a need to write a small utility in bash.
But ran into a problem. The script uses a lot of variables and if several people run the script at the same time, then the one who launched it last will interfere with the work of the first one by overwriting the values ​​of the variables.
As an example:
There is a number variable, the object number from the database is written to it when performing a search.
Naturally, when two employees launched the script, the first one executed the request and the value of the number variable became equal to 100, then the value of this variable is used more than once.
But when the second employee also executes the request, he overwrites the value of the variable. This interferes with the work of the first employee.
Is it possible to somehow isolate employees using bash? So that they do not interfere with each other.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2017-10-17
@Natan4ik

What variables are we talking about?
Would a lockfile be suitable for you ?

I
Ilya Sukhov, 2017-10-17
@TovarischSuhov

In theory, they will not be overwritten anyway: each script runs in its own bash process, and if the variables are not exported, there should be no problem. If you need to limit the number of simultaneously running scripts, then flock can help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question