Find and execute shell scripts in multiple sub directories in parallel


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and execute shell scripts in multiple sub directories in parallel
# 1  
Old 08-28-2011
Find and execute shell scripts in multiple sub directories in parallel

I have one parent directory and within that parent directory there are several other sub-directories and within those sub-directories there are several other "large number" of sub-directories.

All the sub directories have a shell script in them with a common file name execute_command.sh I want to execute all those shell scripts in parallel from within my parent directory.

I tried this but it does not work:

Code:
find . -type d -exec sh execute_command.sh {} \;

I am using Linux with BASH.
# 2  
Old 08-28-2011
From the parent directory u can run

Code:
 
find . -name <script_name> | ksh

This User Gave Thanks to shipra_31 For This Post:
# 3  
Old 08-28-2011
It does not seem to work. Looks to me that this command can run as root user. Let me try out more options and if I succeed, I'll paste my code here. But my requirement is to run all the scripts in parallel rather than in batch mode.
# 4  
Old 08-29-2011
Code:
$ find dir_path -type f -name "execute_command.sh" -exec sh {} \;

This User Gave Thanks to jayan_jay For This Post:
# 5  
Old 09-04-2011
To do it in parallel install GNU Parallel:
Code:
find . -type f -name "execute_command.sh" | parallel

Watch the intro video to learn more: Part 1: GNU Parallel script processing and execution - YouTube
This User Gave Thanks to tange For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute Multiple Scripts and Capture Log Details

Hi All, I have a requirement to execute multiple scripts (say 4) one after the other in one script and capture log details and error messages in a log file below LOG_FILE= FILE.`date ++"%Y%m%d%H:%M:%S"` Script 1 : File_Checkr.sh Script 2 : Pre_Validation.sh Script 3 : Testing.sh Script... (12 Replies)
Discussion started by: Deena1984
12 Replies

2. Shell Programming and Scripting

Executing Multiple Queries in parallel in Shell

I have n number of SQL queries needs to executed in Shell. Result of this query need to assign in a variable. Once all the queries are executed script needs to exit. Sample Query: SQL 1: Select Count(*) from TABLE GROUP BY COL1,COL2 SQL 2: Select Count(*) from TABLE GROUP BY COL1,COL2 ... (2 Replies)
Discussion started by: Niranjancse
2 Replies

3. Shell Programming and Scripting

Execute scripts in Parallel

Hi I want to execute few scripts in Parallel. There is a Master Script (MS.ksh) which will call internally all the scripts we need to run in Parallel. Say there are three set of scripts : ABC_1.ksh --> ABC_2.ksh --> ABC_3.ksh (execute ABC_2 when ABC_1 is successful ; Execute ABC_3 only when... (6 Replies)
Discussion started by: dashing201
6 Replies

4. Shell Programming and Scripting

Script to execute multiple scripts

Hi All, I have 4 scripts to execute. Each one take anywhere from 3 -9 hours to run depending on what it's doing. I'm running one at a time then check back periodically to see if it's still going and if not, run the other. How can I put these scripts into another script so that they are... (5 Replies)
Discussion started by: bbbngowc
5 Replies

5. UNIX and Linux Applications

how to execute multiple .sql scripts from within a shell script using sqlplus

using sqlplus I want to execute a .sql script that has dbms_output statments in rhe script. I want to write the dbms_output statements from .sql file to a log file. is this possible. thanks any help would be appreciated :wall: (1 Reply)
Discussion started by: TRS80
1 Replies

6. Shell Programming and Scripting

Need to execute different scripts with shell script

Hi All, Am in need of some inputs to overcome the following problem, A tar file(/var/execute/scripts/ that contains different types of scripts(may be perl,shell, python etc...). I have written a shell script which is located @ /var/execute.sh to untar the file in some location say... (1 Reply)
Discussion started by: SMNK
1 Replies

7. Shell Programming and Scripting

Not able to execute many SQL scripts within a shell script

I am using HP-UX: I have written a ksh script where I need to connect to sqlplus and execute few sql scripts. Part of this code is - sqlplus user/temp1234 <<! set serverout on set feedback off set pages 1000 set colsep , set echo off spool /home/supp1/pks/output.csv... (8 Replies)
Discussion started by: Sriranga
8 Replies

8. Shell Programming and Scripting

Shell script to execute commands in individual users' home directories

Hi, I am trying to write a shell script which execute certain commands within certain folders in each user's home directories I started off with a bash script - #!/bin/csh -f su -l cvsusr1 cvs -d /home/cvsadm/repository status But the shell script finishes immediately after... (1 Reply)
Discussion started by: rupa_lahiri
1 Replies

9. Shell Programming and Scripting

Execute multiple commands in a find

I am checking that a file is older than a reference file that I build with a touch command before processing it. If it is not old enough, I want to sleep for an hour and check again. My problem is if it is old enough to process, I want to exit when I am done, but I cannot find a way to exit... (2 Replies)
Discussion started by: prismtx
2 Replies

10. UNIX for Dummies Questions & Answers

editing sqlplus id@passwd in multiple scripts, users and directories

hi all, i was given by my supervisor a task to search for scripts which contain oracle sqlplus i.e "myusername/mypasswd @myDB" in every /home/userfolder, which are, all the scripts made by different user. I've done some find command to search string for sqlplus, but it may up too long to respond.... (8 Replies)
Discussion started by: Helmi
8 Replies
Login or Register to Ask a Question