Shell script for scheduling


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script for scheduling
# 8  
Old 01-23-2005
::)smile

#! /usr/bin/bash
/path/to/job1 &
/path/to/job2 &
/path/to/job3 &
wait
/path/to/job4 &
/path/to/job5 &
/path/to/job6 &
wait
exit 0

join/to/job 1 % ...
pico
wait
exit 0,1
# 9  
Old 01-24-2005
Hi:
Could you explain what does this extra code does.
-------
join/to/job 1 % ...
pico
wait
exit 0,1
-------
Thanks,
Chandu
# 10  
Old 01-28-2005
Quote:
Originally Posted by chanduhyd4u
This is actually our project requirement. I described here it as a small assignment, but actually we have about 150 procedures and some of them can be run parallally and some of them have dependency. Our objective is to write a shell script to schedule this task. I have no idea about how to start with and request your ideas/suggestions.
What a complicated request! You are trying to code a work flow system in a shell script.

If you're new to UNIX, you will certainly have trouble wrapping your arms around someone else's scripts.

Conceptually, here is what you want to do:

Your first goal is to build the framework for interacting with Oracle. I find that communicating to Oracle with a sqlplus coprocess to be very easy to control your various interactions.

Code:
sqlplus -s /nolog |&

Then you send messages to the coprocess.

Code:
print -p "connect un/pw@db"
print -p "prompt 'sql complete'"

Then you can read back Oracle's responses simillarly as follows:
Code:
while read -p LINE
do
    # This is necessary so that the loop doesn't freeze waiting for more output
    if print $LINE | grep 'sql complete'
    then
        break
    fi
    # More result analysis...
    if ...
done

This works for PL/SQL code wrappers, dynamic SQL, etc. In fact, the only thing that isn't so great is if you have 1000s of lines of results and you want to process them with the while read command.

The next thing that you need is a mechanism to drive your execution priorities. This can be done with one or more tables and defining some basic rules. The simplest will be the processing order.

You'll also want to identify the don't care procedures that can run in the background. This is more tricky but can be done fairly easy. I did this for my current project where I need to bulk load data using sqlldr and where I can't use direct path loads (this works at blazingly fast speeds; my tests showed nearly one million records per minute in one test case). I split the task into five threads and each thread loads a different portion of the file. You can sychronize information by wrapping the command in a pair of braces which causes the code to execute in a subshell. The direct the output to a common file for analyzing the results.

Code:
{
    sqlldr un/pw@db ...
    # put any kind of stuff inside the braces that will help you digest the processing results
    print result code=$?
} >> some_output_file_common_to_all_threads &

# save the process ID
mypidlist="$mypidlist $!"
...
# later on, when you want to synchronize the threads you have to wait on the background pids.
# The following wait is more reliable than the unix wait (for me that is  :( )
while [ $(ps -p $(print ${mypidlist} |
          tr -d ' ' |
          nawk '{print substr($0,1,length($0)-1)}') |
          wc -l) -gt 1 ]
do
   sleep 2
done

# now process information related to your thread's output
while read LINE
do
    ...
done < some_output_file_common_to_all_threads

Your serially executed procedures/tasks run in the coprocessor and your "don't care procedures" can be run in their own sqlplus sessions independent of the coprocessor.

Coprocess exacmple:
Code:
print -p "SET SERVEROUTPUT ON"
print -p "BEGIN"
print -p "    call_my_proc;"
print -p "END;"
print -p "/"
print -p "PROMPT 'sql complete'"

while read -p LINE
do
   ... same as before
done

Background example:
Code:
{
sqlplus -s /nolog <<EOF
connect us/pw@db
SET SERVEROUTPUT ON
BEGIN
     call_my_proc;
     call_another_one_if_you_like;
     DBMS_OUTPUT.PUT_LINE ('whatever message you want');
END;
/
EOF
} >> some_other_file_as_before &
mypids="$mypids $!"

If you really want to monitor status of the background procedures, use the facilities with Oracle for long oeprations and then use your coprocessor to periodically query the information. Or you can use your own table, whatever you want but the Oracle longops facility is designed for this simple kind of job communication.

This can also serve as a mechanism for synchronizing your background tasks.

This is a very simplistic description for solving your very complex requirement but I use this kind of technique now with great success.

Thomas

Last edited by tmarikle; 01-28-2005 at 07:07 PM..
# 11  
Old 08-12-2008
Reading from Co-process

I have an SFTP coprocess whose output is redirected to a file (as shown in the script below). Now how can I read the output of the coprocess:

exec 4>$FTPLOG
sftp nakarapu@serverx >&4 2>&4 |&
print -p mget $filename
print -p !echo "The FTP is complete"
read -p LINE
echo $LINE
print -p bye
wait

What changes to the above code can make it read the LINE from the coprocess.

(Btw, this is an attempt to synchronize with the coprocess. If you have a better way to know when the coprocess finishes the ftp, please let me know.)


Thanks in advance
Naveen Akarapu
# 12  
Old 08-12-2008
Quote:
Originally Posted by akar_naveen
I have an SFTP coprocess whose output is redirected to a file (as shown in the script below). Now how can I read the output of the coprocess:

exec 4>$FTPLOG
sftp nakarapu@serverx >&4 2>&4 |&
print -p mget $filename
print -p !echo "The FTP is complete"
read -p LINE
echo $LINE
print -p bye
wait

What changes to the above code can make it read the LINE from the coprocess.

(Btw, this is an attempt to synchronize with the coprocess. If you have a better way to know when the coprocess finishes the ftp, please let me know.)
I have never been able to get ssh, scp, or sftp to work via a coprocess due to how it forks a child process. You need to use expect or Perl expect; that's what I have used.

T
# 13  
Old 08-12-2008
expect is not installed in our systems.

But I am guessing there must be some kind of I/O indirection that allows me to read the output of the coprocess.
# 14  
Old 08-12-2008
Quote:
Originally Posted by akar_naveen
expect is not installed in our systems.

But I am guessing there must be some kind of I/O indirection that allows me to read the output of the coprocess.
Code:
read -p LINE

That would normally do it but, as I said, secure shell commands fork a child process and that I/O can't be captured by the coprocess. Sorry.

t
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Scheduling a script

Hi, I have my script in below path in UNIX /storage/sas_source/SDTM-Development/FileWatcher/filewatcher.sh I want to schedule it to run every 30 secs. Please let me know the steps to do it. Thanks. (7 Replies)
Discussion started by: prats_7678
7 Replies

2. Shell Programming and Scripting

Error while scheduling the shell script

I am getting the below error while scheduling the job.Why? 00 30 * * * /arbor/integ_fx/rahul_raj/itsr_5652_v2/it.sh /arbor/integ_fx/rahul_raj/itsr_5652_v2 "/tmp/crontabBvaWiv" 47 lines, 2412 characters 00 30 * * * /arbor/integ_fx/rahul_raj/itsr_5652_v2/it.sh ... (2 Replies)
Discussion started by: rafa_fed2
2 Replies

3. Shell Programming and Scripting

Shell script scheduling in cronjob

Hi, I have developed a file deletion script and scheduled it in cronjob to run daily at 5:00 AM. But the script is not running automatically any day. However when I run the script manually at any time, it runs successfully. This is how the cron looks like : 0 5 * * *... (5 Replies)
Discussion started by: jhilmil
5 Replies

4. Shell Programming and Scripting

Scheduling a Ksh script

All, Running the below script independently is working fine with no issue but once I am scheduling it in cron on my Linux environment it is not working. Can anyone look into this and let me know what I have to modify here to schedule it properly. 09 03 * * 4 ksh 'cd... (1 Reply)
Discussion started by: Oracle_User
1 Replies

5. UNIX for Dummies Questions & Answers

Scheduling a script by using Crontab

Hi, I need to schedule a script in crontab which should run at 01:00 am in the morning and should run for every 15 days in a month. How to schedule this by using crontab? Many thanks. Rgds, (13 Replies)
Discussion started by: venkatesht
13 Replies

6. UNIX for Advanced & Expert Users

Scheduling a script other than crontab

Hi, How can we run/schedule a shell script. Since there is no access to cron at this point of time we have to think other way out to run a script every hour. How can we achieve this. Need advice. How about using sleep,autosys etc...the script should trigger off every hour...which sends... (3 Replies)
Discussion started by: noorm
3 Replies

7. Solaris

Passing arguments to a shell script from file while scheduling in cron

Hi, I have a shell script Scp_1.sh for which I have to pass 2 arguments to run. I have another script Scp_2.sh which in turns calls script Scp_1.sh inside. How do I make Scp_1.sh script to read arguments automatically from a file, while running Scp_2.sh? -- Weblogic Support (4 Replies)
Discussion started by: weblogicsupport
4 Replies

8. UNIX for Dummies Questions & Answers

Problem with scheduling a shell script on cygwin using cron

Hi, Before I start, I would like to inform that, I went through all FAQs and other threads before posting here. I 'm trying to schedule a shell script on cygwin using cron. No matter what I do I don't seem to get the cron job executing my bash script. My script is temp.sh echo `date` >... (4 Replies)
Discussion started by: shash
4 Replies

9. Shell Programming and Scripting

script scheduling

Hi, I have a ksh scrip (x) that scans a directory and does actions when a file arrives in this directory. My question is what is the best way to schedule x? 1. Use cron tab and create a task running forever 2. Creat another ksh script (y) that runs (x) in a non-terminating loop Which... (2 Replies)
Discussion started by: GNMIKE
2 Replies

10. Shell Programming and Scripting

scheduling script to run another script on Solaris

Hi everyone, I am trying to automate one process on Solaris OS. This is what happens at the moment. Every night at 19:30 and every hour after that we run a script that checks the status of databases. That script runs and prints if db's are OK at the end it states how many were down. I am... (3 Replies)
Discussion started by: andrei
3 Replies
Login or Register to Ask a Question