Help with write a master script to automatic 1000 process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with write a master script to automatic 1000 process
# 1  
Old 03-04-2014
Help with write a master script to automatic 1000 process

Hi,

I just random create 1000 folder which range from 0-20,000 . Inside all the folder, I have copy over the same program named as run.sh to run in each folder.

Can I know that how to write a master script to let it automatic run the "run.sh" in each different random folder create?

Some random folder create :
Code:
500/
18805/
641/
.
.
.

If just run the "run.sh" in one folder, I will use the following command :
Code:
sh run.sh > run_log

But it a bit tedious if I have 1000 different folder need automatic run the same program.

I was thinking do use "for ... do ... done ...", but I don't have much idea so far Smilie
# 2  
Old 03-04-2014
Why don't you, inside the loop, cd into the directory represented by the loop variable, sh run.sh > run_log, and then cd back to the parent dir, ready for the next loop?
# 3  
Old 03-04-2014
Unless we are missing something here your for .. do .. done loop will be like this:

Code:
for folder in [0-9]*
do
   if [ -d "$folder" ]
   then
      cd "$folder"
      sh run.sh > run_log
      cd ..
   fi
done

Why copy run.sh to each folder?
You should be able to load the script from any path e.g. sh ../run.sh > run_log or sh ~/bin/run.sh > run_log.
Is each slightly different in some way?
# 4  
Old 03-04-2014
Hi RudiC,

I have thinking to do something like :
Code:
for f in 500/ 18805/ 641/ ......
do
cd $f
sh run.sh > run_log
cd ..
done

I just not sure is there any smarter way to edit the "for f in 500/ 18805/ 641/ ......
" instead of I list out all the 1000 folder name in first line?

Thanks for any advice.

---------- Post updated at 08:15 PM ---------- Previous update was at 08:13 PM ----------

Hi Chubler_XL,
Code:
sh run.sh > run_log

can only run and work in each folder separately.
It can't run at any other path. That was because the input file in each folder is slightly different. But they all must use "run.sh" to extract out the result.

I will try out your script.
Hope it works Smilie
# 5  
Old 03-04-2014
Quote:
Originally Posted by perl_beginner
Hi Chubler_XL,
Code:
sh run.sh > run_log

can only run and work in each folder separately.
It can't run at any other path. That was because the input file in each folder is slightly different. But they all must use "run.sh" to extract out the result.

I will try out your script.
Hope it works Smilie
Where the script is loaded from has no bearing on what directory it runs in, if you change to directory ./1008 and run /usr/local/bin/run.sh it will still execute in the 1008 folder even though the script is loaded from another folder. You will save yourself a lot of grief later if you keep 1 version of the script as you won't have to update 1000 different scripts for every change, try putting run.sh in a bin/ directory under your HOME and then run:

Code:
for folder in [0-9]*
do
   if [ -d "$folder" ]
   then
      cd "$folder"
      sh $HOME/bin/run.sh > run_log
      cd ..
   fi
done

I think you will be pleasantly surprised.
This User Gave Thanks to Chubler_XL For This Post:
# 6  
Old 03-05-2014
Hi Chubler_XL,

Your idea is awesome Smilie
I'm trying out both of your advice.
It works fine so far ^_^

It is still running at the moment.

Thanks a lot and again.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

2. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX Desktop Questions & Answers

How can I replicate master master and master master MySQL databse replication and HA?

I have an application desigend in PHP and MySQl running on apache web server that I is running on a Amazon EC2 server Centos. I want to implement the master-master and master slave replication and high availability disaster recovery on this application database. For this I have created two... (0 Replies)
Discussion started by: Palak Sharma
0 Replies

4. HP-UX

System not responding and Automatic process kill

Hi All, One of our servers stopped responding , unable to take any logins into it, the response is almost nil...later it resumed Also during this time one of our application processes which was costly on memory got killed..is it an OOM kill? Would like to know to know how to avoid such... (4 Replies)
Discussion started by: baanprog
4 Replies

5. Shell Programming and Scripting

Help to write a script or program to automatic execute and link input file data

Output file template format <input_file_name>a</input_file_name> <total_length_size>b</total_length_size> <log_10_length_size>c</log_10_length_size> Input_file_1 (eg. sample.txt) SDFSDGDGSFGRTREREYWW Parameter: a is equal to the input file name b is equal to the total length of... (2 Replies)
Discussion started by: perl_beginner
2 Replies

6. Shell Programming and Scripting

How to write an expect script to check if a process is running?

I'm new to expecting and i want to create a script to ssh to a device,check is a process is running and display that the process is running or not.This is what i have so far After executing this script i get an error. #!/usr/bin/expect set timeout -1 set ip "machine ip goes here" set... (5 Replies)
Discussion started by: icchi
5 Replies

7. Shell Programming and Scripting

[REQ] Automatic script kill process

HI, I'm using CentOS 5.1 x86_64, CPanel .. a lot of my users used too much resource, i want to write a script to kill all of them. Eg: LFD always notify me: Time: Sun Apr 27 07:40:08 2008 Account: xxxx (my user) Resource: Virtual Memory Size Exceeded: 110 > 100 (MB)... (3 Replies)
Discussion started by: onisoc
3 Replies

8. UNIX for Dummies Questions & Answers

Want to process file in 1000 record increments

I have a file that varies in the # of records. I want to read 1000 records, do something, read the next 1000 records, do something, going in 1000 increment chunks, and then finish up with whatever is left over at end of file. (1 Reply)
Discussion started by: Tsamp
1 Replies

9. Shell Programming and Scripting

need help to write script to check the process health and automatically restart it

I am working on a project, which need to constantly watch the process, and check its status, if it was dead, it should be restart automatically. Please kindly refer me to URL which teach how to write this kind of script, or service. Thanks. (1 Reply)
Discussion started by: dragondad
1 Replies
Login or Register to Ask a Question