How to run same script in parallel from on session? e.g. 5x
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to run same script in parallel from on session? e.g. 5x
Hi,
I have a shell script to refresh some databases. Currently I open 5 sessions and to execute the five scripts.
Today, as test, I tried to see if I could run two refreshes simultaneously from one session using the '&':
. /refresh.ksh db1 &
. /refresh.ksh db2
The first one ran and the second one started only after the first one was finished. Could it be that the script refresh.ksh contains many commands and those are not pushed to the background? If so, what's the best approach to getting 5 db's refresh simultanously from on session?
From what I know of screen (which I admit is limited) it is similar to the way DVTM works, in that it breaks up a console/terminal into "sessions" or separate sub-instances.
As mentioned above, maybe the command or operation you are doing will only work serially anyhow, because it will only refresh one DB at a time, so this may be irrelevant; but:
if you're looking for a way similar to `screen` to run multiple processes within one terminal session, look up DVTM (Dynamic virtual terminal manager) -- it acts like a tiling window manager, except it's for inside terminal environments. I've used it both in an "xterm" type of terminal emulator, and also in a VT outside of X, and it does what it claims to do.
should definitely fire off the first one into the background and immediately start the second one. I think you need to check your code and/or how you're checking for parallel running. There's nothing wrong with that code as is...
IMPORTANT: just noticed due to my copy n paste that it looks like you've got a space between the '.' and the '/'; this will cause it to source the code into the current shell, NOT what you want.
Remove the space and try again; also, post inside code tags next time please.
For what you're wanting to do, backgrounding ~should~ work. Failing that provided that the refresh.ksh can be run simotaniously (eg it doesn't block in some manner) then screening the processes will let you do that. I wrote a fairly good basic tutorial on screen a while ago.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.