I am new to scripting. I have 21 directories to compress and copy to another location. I want to run 4 process in parallel and if one process complete then start another one. like wise 21 directories should complete.
I got some idea from following post. bash script to check running process
I need this to add, if number of running service < 4, then start another process.
Please help me regarding this matter.
My script is as follows. Here I used ping command to test process. If this is working I can arrange it to copy command.
job.sh
#!/bin/bash cat my.txt |while read line do run_count=`ps eax | grep ping | grep -v grep | wc -l` if [ 4 -gt ${run_count} ] then /home/cms.sh $line & fi done cms.sh
#!/bin/bash value=$1 cmd=ping host=yahoo.com $cmd -c $1 $host >> log-$1.txt my.txt
100 250 150 174 182 140 320 139 150 120 110 99 156 180 230 132 123 119 156 149 162 If I run this, it is starting to run 4 process using first 4 lines in my.txt. After finish that initial 4 processes it will not continue remain values in my.txt.
Please let me know where I did mistake.
Thank you in advance!!!