Hello
I havea simple requirement, But I do not know to execute in ksh.
Here is the reqt.
I have aseries of jobs that has to run in certain order

-First, Run- nuphup Task1.sas & and nohup Task2.sas & parallely(simultaneously)
-Second- Wait till Task1.sas and Task2.sas is complete (RC=0)
-Third-When the above 2 tasks are complete execute nohup Task3.sas &, nohup Task4.sas &, nohup Task5.sas & in parallel (sumultaneously)
-Fourth- When the Third job completes (RC=0) execute nohup Task6.sas &

Once all the tksks are complete -email that all tasks are complete

Can you help me create a .ksh script to accomplish the above

Tahnk you
M

Why ksh specifically? Could you use bash instead?

Hi Bash is also fine.

Here is a script to get you started. It illustrates what you need to do with mock commands and without verifying the return values of the spawned processes. You will have to fill in

  1. The commands to run
  2. Logic to check the return values from those commands

The only thing I didn't touch was the email. For that you can easily script your favorite terminal-based mail client (such as mutt). Just how will depend on your client.

Sorry, adding a code snippet to the previous post via an edit seems to be broken for me. I'm pasting the mentioned snippet here:

#!/bin/bash

# Encapsulate each requirement in a function
part1() {
    CMD1="sleep 2"
    CMD2="sleep 4"
    ${CMD1} &
    PIDS[0]=$! # assign PID of last run command
    ${CMD2} &
    PIDS[1]=$!
    echo "Waiting on ${PIDS[0]} and ${PIDS[1]}"
    wait ${PIDS[0]} # wait for child of this shell
    RES[0]=$?       # the result of wait is the exit status of the command
    wait ${PIDS[1]}
    RES[1]=$?
    echo "Return values: ${RES[0]} ${RES[1]}"
}

echo "Starting part1... (`date +%s`)"
part1
echo "Part1 complete... (`date +%s`)"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.