Multiple shell scripts executed in one script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple shell scripts executed in one script
# 1  
Old 11-27-2013
Multiple shell scripts executed in one script

Hi every one, i am new to shell script. my people given a task to write a shell script that should execute number of shell scripts in that. in that, if any shell script is failed to execute, we have to run the main script again, but the script should start execute from the failed script only..
it is very urgent task ,

Thanks in advance

note: main.csh is main script.. in this main.csh number of script need to execute like one.csh, two.csh, three.csh.. if two.csh fails, if we run main.csh, it should execute two.csh only..

kindly help me
# 2  
Old 11-27-2013
Have you started with something??
# 3  
Old 11-27-2013
i have tried like this , but something it is not working fine,..
Code:
echo " script one is executing " | csh one.csh
if [ $? -eq 0 ]
then
echo "one.csh OK..."

sleep 5
csh two.csh
if [ $? -eq 0 ]
then
echo "two.csh OK..."

sleep 5
csh three.csh
if [ $? -eq 0 ]
then
echo "three.csh OK..."
else
echo "three.csh NO..."
fi

else
echo "two.csh NO...."
exit 0
fi

else
echo "one.csh NO...."
exit 0
fi

==========================================
Code:
$ sh main.csh

/tmp/smh/test1
one.csh OK...
BBBBBBBB
two.csh OK...
three.csh: lsdlfi: not found.
three.csh NO...
========================
$ cat one.csh
pwd
-----------------------------
$ cat two.csh
echo "BBBBBBBB"
-----------------------------
$ cat three.csh 
lsdlfi

giving solution is appreciated

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data...

Last edited by vbe; 11-27-2013 at 05:19 AM..
# 4  
Old 11-27-2013
Quote:
Originally Posted by Madhu Siddula
i have tried like this , but something it is not working fine,..
.....
Code:
$ sh main.csh

/tmp/smh/test1
one.csh OK...
BBBBBBBB
two.csh OK...
three.csh: lsdlfi: not found.
three.csh NO...
========================
$ cat one.csh
pwd
-----------------------------
$ cat two.csh
echo "BBBBBBBB"
-----------------------------
$ cat three.csh 
lsdlfi    # ----> what is this ?

giving solution is appreciated
# 5  
Old 11-27-2013
That approach seems a bit strange to me. The script extensions imply you are using the csh shell, but you're running main with plain Bourne sh. And, why are you piping that echo to one.csh?

If two.csh fails, do you want to run it again immediately, or do you want to finish the main script (i.e. 3,4,5), and then run main again with just two.csh?
# 6  
Old 11-27-2013
Multiple shell scripts executed in one script

i want to finish the main script (i.e. 3,4,5), and then run main again with just two.csh..
# 7  
Old 11-27-2013
As you did not comment on the shell you use, here's a bash snippet that you may adapt if need be. It repeats the failed scripts once, then stops:
Code:
var=${1:-1 2 3 4 5}
for i in $var
  do case "$i" in
        (0)     exit ;;
        (1)     one;   [ $? -eq 0 ] || new="$new 1" ;;
        (2)     two;   [ $? -eq 0 ] || new="$new 2" ;;
        (3)     three; [ $? -eq 0 ] || new="$new 3" ;;
        (4)     four;  [ $? -eq 0 ] || new="$new 4" ;;         
        (5)     five;  [ $? -eq 0 ] || new="$new 5" ;;
     esac
  done   
[ "$new" ] &&  exec ./main "$new 0"

This User Gave Thanks to RudiC 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

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

2. Linux

Multiple process found when executed from script

Hi All, I came across a weird scenario which i couldnt explain why. As part of script which is run as /bin/sh shebang, we are trying to check if there is any process that runs with the same name ignoring the current process and kill it. But for some reason, there are 2 process returned as part... (1 Reply)
Discussion started by: varathaneie
1 Replies

3. Shell Programming and Scripting

Multiple shell scripts executed in one script

Hi every one, i am new to shell script. my people given a task to write a shell script that should execute number of shell scripts in that. in that, if any shell script is failed to execute, we have to run the main script again, but the script should start execute from the failed script only.. it... (1 Reply)
Discussion started by: Madhu Siddula
1 Replies

4. Shell Programming and Scripting

Shell script not getting executed

Hi As per my requirement when I run . ./file.sh am getting the following error -bash:ELF: command not found when i execute as ./file.sh it is getting executed.How to resolve this. Thanks in advance. (3 Replies)
Discussion started by: pracheth
3 Replies

5. Shell Programming and Scripting

Shell script executed from Informatica ETL tool is spawning 2 processes for one script

Hi, I am having a shell script which has a while loop as shown below. while do sleep 60 done I am executing this script from Informatica ETL tool command task from where we can execute UNIX commands/scripts. When i do that, i am seeing 2 processes getting started for one script... (2 Replies)
Discussion started by: chekusi
2 Replies

6. UNIX for Advanced & Expert Users

Procedure to be executed from shell scripts

Hi, I am looking for a script wherein i will be able to execute below procedures one by one in line and next procedures starts only when the previous one completes and also after execution of each procedure i will be getting a automted mail as "PL/SQL PROCEDURE SUCCESSFULLY EXCETUTED". ... (1 Reply)
Discussion started by: sv0081493
1 Replies

7. Shell Programming and Scripting

help with shell script executed by php.

I made a shell script to execute a server in screen mode. # start server screen -d -m -S Test ./application echo "Program Started Successfully" than I'm executing it from php by echo shell_exec('/home/script.sh'); and it is giving me this error. "cannot make directory... (1 Reply)
Discussion started by: dmallia
1 Replies

8. 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

9. AIX

Help - Need simple example of VI executed in shell script

Please help - I have seen others ask this question but I need a simple example of using vi in a shell script. Once I enter VI the shell script does not execute the next commands until I q!. I invoke VI and start the edit process. I want to go to the third line and replace a character with a new... (2 Replies)
Discussion started by: corsart
2 Replies

10. Shell Programming and Scripting

Shell script doesn't get executed using crontab

I have the following crontab entry to run a shell script for every 30 minutes of every day: 30 * * * * $HOME/main.sh > $HOME/main.log 2>$HOME/error.log after I created the crontab file I have also done: $crontab my_crontab I also check to make sure it exists, by using the following... (11 Replies)
Discussion started by: radhika
11 Replies
Login or Register to Ask a Question