Visit Our UNIX and Linux User Community


Recursive Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Recursive Shell script
# 1  
Old 06-07-2011
Recursive Shell script

I'm trying to run the script below recursively but it is generating multiple and simultaneous processes. how do I do to start same script again (last line of my script) only after he had just run entirely?

The file name is bachup.sh

I am using this command:

Code:
# / bin / bash /
 rsync-avzu - delete-excluded / home / user / mnt / backup /
 wait
 sh / etc / backup.sh


Last edited by pludi; 06-07-2011 at 02:53 PM..
# 2  
Old 06-07-2011
bash has the interesting exec command which allows you replace the current shell with the command, this sends a HUP to all processes running in the shell
ie
Code:
exec /bin/bash  /etc/backup.sh

# 3  
Old 06-07-2011
Try
Code:
wait $$

# 4  
Old 06-07-2011
did work.

tks

---------- Post updated at 11:42 AM ---------- Previous update was at 11:02 AM ----------

when i type
Code:
exec /bin/bash  /etc/backup.sh

it stops all running process?

is I want to run more than one scrip, but one at time I tried to use:
Code:
exec /bin/bash  backup1.sh
exec /bin/bash  backup2.sh
exec /bin/bash  backup3.sh

but only runs backup1.sh

what am I doing wrong?

Last edited by pludi; 06-07-2011 at 02:53 PM..
# 5  
Old 06-07-2011
From the man page of bash:
Quote:
exec [-cl] [-a name] [command [arguments]]
If command is specified, it replaces the shell. No new process is created. The arguments become the arguments to command.
So the first exec replaces the current process (read: your shell script) and no further code from it will be executed. Just start them without it, and it should work as expected.
# 6  
Old 06-07-2011
so how do I run more process but start the second just when the first is finished?

Code:
exec /bin/bash  backup1.sh exec /bin/bash  backup2.sh exec /bin/bash  backup3.sh


Last edited by pludi; 06-07-2011 at 03:11 PM..
# 7  
Old 06-07-2011
First, please start using [CODE] tags when posting code, etc...

Second, as I said before, and DGPickett said here, leave out the exec. It replaces the current script with the one you're calling, and it won't run any part of the original script from there on. Nothing. Nada. And as long as you don't put any script into the background the shell will dutifully wait for it to finish before starting the next one.

Previous Thread | Next Thread
Test Your Knowledge in Computers #702
Difficulty: Medium
The MySQL LIKE operator is a logical operator that tests whether a string contains a specified pattern.
True or False?

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. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

4. Shell Programming and Scripting

Help with creating recursive unzip script

Hello. I am trying to create a script that recursively looks at my folder structure, and extracts any .7z files that have not already been extracted yet. I know that all .7z files only have a single .txt file in them, and the only .txt file in any directory would be from that .7z file. I am... (3 Replies)
Discussion started by: Davinator
3 Replies

5. Shell Programming and Scripting

help with recursive handbrake script

I have a batch of mkv video files I would like to transcode to a more compressed format. After spending a significant amount of time experimenting with various parameters I think I have found the handbrake settings that give the best compromise. I now want to construct a simple bash script... (4 Replies)
Discussion started by: jonesal2
4 Replies

6. Shell Programming and Scripting

Logic needed to recursive looping in the script

Hello i have a requirement where in a file i will get string. The length could be from 1 to 20. if the string is less than 6 characters ( ex: ABCD) . i need to append 'X' on right hand side to make it 6 characters (ex: ABCDXX). if suppose i get the same string from the file as ABCDXX then i... (5 Replies)
Discussion started by: dsdev_123
5 Replies

7. Shell Programming and Scripting

Recursive call to find files and directories in Shell script from current path.

################################################################ Copy this script to your path from where you want to search for all the files and directories in subdirectories recursively. ################################################################# code starts here... (2 Replies)
Discussion started by: Ramit_Gupta
2 Replies

8. Shell Programming and Scripting

Script problem due to recursive directories Help please

Hello everyone , I am looking for a better solution then the one I have created for the my Task The task is: Create an automated script that will check for Uploads in a specified Directory and move them to another specified Directory if the files are completely uploaded. Files are FTP'd to... (2 Replies)
Discussion started by: robertmcol
2 Replies

9. Shell Programming and Scripting

Recursive pid script

I'm trying to create a script that allows me to determine all the pid's that spawned from an original process(ie - who's running this command).... I've created a script that searches the processes running based on an argument passed the script. It then is to get the parent pid and look that... (3 Replies)
Discussion started by: jbarnhar
3 Replies

Featured Tech Videos