0

I have a script which in turn triggers 4 more scripts in another server sequentially. My script is waiting until the first script completes in target server and then triggers the second one. Below is the code

SCB_CMD=/sc/db2home/scbinst/bin/reload_scrpt1.sh
SCB_LOG=/sc/db2home/scbinst/log/reload_scrpt1.log

echo `date` "Executing $SCB_HOST:$SCB_CMD ..." 

ssh $SCB_HOST "$SCB_CMD | tee $SCB_LOG"

RC=$?

#---------------------------------------------------------------------------
# -- Check for errors
#---------------------------------------------------------------------------
if [ $RC -ne 0 ]
then
  echo `date` "!error occurred executing SCB load script1!" 

  exit 99
fi
#---------------------------------------------------------------------------
SCB_CMD=/sc/db2home/scbinst/bin/reload_scrpt2.sh
SCB_LOG=/sc/db2home/scbinst/log/reload_scrpt2.log

#---------------------------------------------------------------------------
# -- Execute the remote load script
#---------------------------------------------------------------------------

echo `date` "Executing $SCB_HOST:$SCB_CMD ..." 

ssh $SCB_HOST "$SCB_CMD | tee $SCB_LOG"
--------------------------------------------

Is there a way to trigger all these four scripts in parallel in target server?

2 Answers 2

1

& at the end of a command puts the job in background.

I'd rewrite my script

connector.sh

#!/usr/bin/env bash

echo `date` "Executing $1:$2"
# 1 host, 2 cmd, 3 log
ssh $1 "$2 | tee $3"

add the runner.sh script

#!/usr/bin/env bash
connector.sh 127.0.0.1 /sc/db2home/scbinst/bin/reload_scrpt1.sh /var/log.log &

connector.sh 127.0.0.1 /sc/db2home/scbinst/bin/reload_scrpt2.sh /var/log.log &

connector.sh 127.0.0.1 /sc/db2home/scbinst/bin/reload_scrpt3.sh /var/log.log &
1
  • 1
    Make connector a function in runner.sh. There's no need for a separate script. Commented Apr 4, 2017 at 7:44
0

You can launch the jobs in parallel (I assuming the ssh commands work on the command line had you run them individually, meaning, it's not any issue with the remote vis-a-vis local m/c issue.

for i in `seq 1 4`; do
   SCB_CMD=/sc/db2home/scbinst/bin/reload_scrpt${i}.sh
   SCB_LOG=/sc/db2home/scbinst/log/reload_scrpt${i}.log

   echo `date` "Launching $SCB_HOST:$SCB_CMD ..."
   ssh "$SCB_HOST" "$SCB_CMD | tee $SCB_LOG" &

   sleep 1
done

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.