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

Have you started with something??

i have tried like this , but something it is not working fine,..

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

==========================================

$ 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

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?

i want to finish the main script (i.e. 3,4,5), and then run main again with just two.csh..

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:

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"
1 Like