How to determine the completion of a background process to trigger something else?
I've been thinking about a peculiar problem, and so far haven't been able to find out a convincing solution to that.
To put it simply, I have a shell script (assume it to be parent_script.sh), calling another shell script (child_script.sh) 5 times, in nohup mode to be executed in the background. The parent script is something like this
For each run, child_script generates 10 files in a particular folder. So for a single run, parent_script.sh will be having 50 files generated.
After all the 50 files are created in that folder, I need to rename these files. For instance, if the files are created as abc.txt, def.txt.....xyz.txt, then after renaming, these will be abc_01.txt, def_02.txt....xyz_50.txt.
Now in order to start the renaming process, I've thought of adding a small code block in the parent_script.sh, something like below
This will ensure that the renaming process will wait until all the 5 parallel threads get completed, then start renaming the files, and then finish the parent script.
My problem is, this file generation process for the 5 threads may take quite a few hours to get completed, may be 2-3 hours on an average. But as per the requirement, the parent script is invoked once every hour. So it may very well happen that at a time more than 5 parallel threads of child_script.sh are running, for multiple executions of the parent script. In such a scenario, the count of running processes of child_script.sh will never be zero.
What can be an alternative way out for this? I'm not much of an advanced unix user, and any help will be much appreciated.
N.B. for each hourly run of the parent script, the renaming sequence of 1 to 50 will recycle, i.e. for first hour, the files will be abc_01.txt...xyz_50.txt, similarty for the files created in the second hour will be named ABC_01.txt...XYZ_50.txt
Hi,
I am creating a script in which we will check a folder. If any file placed inside the folder, script will move the file to another folder and Trigger etl process.
Now the issue is that the script should continously check the presence of file inside folder after every minute or hour. So how... (1 Reply)
Hello All,
I am using Linux. I have two scripts:
inner_script.ksh
main_wrapper_calling_inner.ksh
Below is the code snippet of the main_wrapper_calling_inner.ksh:
#!/bin/ksh
ppids=() ---> Main array for process ids.
fppids=() ---> array to capture failed process ids.
pcnt=0 --->... (5 Replies)
Hi,
I have written a menu driven shell script in which as per the choice, I run the another script on background.
For eg:
1. get info
2)process info
3)modify info
All the operations have different scripts which i schedule in background using &.
However I wish to display the error... (0 Replies)
Hi,
I am willing to build a script that does a "ps-ef" or "top" on a specific process, and if it finds it running to start another process.
Any suggestions to do this in a optimized way?
Thanks! (2 Replies)
Hi,
I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming.
So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Hi all,
This is my first post.
I am new to unix scripting.
My requirement is as follows :
We are using a financial backoffice application.
Now at the end of day we have send users a status report stating all timings of EOD processes for all countries.
I need timings for following... (0 Replies)
I have my unix machine configured to run locate.updatedb on login in the background and after it completes, when I run a command such as ls-- the console returns the results of ls and
+ Done sudo /usr/libexec/locate.updatedbIs there... (3 Replies)
What I need to learn is how to use a script that launches background processes, and then kills those processes as needed.
The script successfully launches the script. But how do I check to see if the job exists before I kill it?
I know my problem is mostly failure to understand parameter... (4 Replies)
Hi,
OS - Unix
Iam doing the following:
after login to the unix box
1. change directory
2. run a shell script "preinstall.sh"
3. This takes apprx 5 mins
4. after which i use to change permission of a file "installhub.sh" (this file is generated from the previous step).
Is there anyway... (2 Replies)
Hello all,
How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename.
Any assistance is most appreciated.
Thanks,
Jim... (10 Replies)