The main way to execute a program from within a program type script is with the eval command in UNIX and the call command in Windows.
It is the Applications Manager program type script that actually runs the program selected in a job definition. While you can use any standard command to execute a program from within a program type script, the command used by Applications Manager program type scripts is 'eval' in UNIX and 'call' in Windows. Eval evaluates parameters, then executes the command.
For SQL*Plus scripts in UNIX, the pipe command is used to direct a string of commands to SQL*Plus.
UNIX Program Type Script Code
In a typical UNIX program type script, the code that executes the program would look as follows (code in bold):
1 :
2 #!/bin/sh
3 #Copyright 2007 Automic Software GmbH
4 # $Header:
/isa/devel/soport/so/dev/sostage/RCS/EXEC-EXECS,v
1.2 1998/02/24 19:06:46 billw Exp $
5 arg="$program `$AW_HOME/exec/ONELINE $par`"
6 eval $arg
7 err=$?
8 if [ -f $file ]; then
9 $AW_HOME/exec/FILESIZE $file $err
10 err=$?
11 fi
12 if [ -f $OUTPUT/$file ]; then
13 file=$OUTPUT/$file;export file
14 $AW_HOME/exec/FILESIZE $file $err
15 err=$?
16 fi
17 exit $err
On the first pass, eval evaluates $program and $par. It then executes the program.
UNIX Pipes
Pipes are used by programs that accept inputs from the standard input device. Normally, standard input would be the user's terminal and/or keyboard. If you pipe output from the program type into the program, then the program is taking its standard input from the program type.
$program <$par
A more complex example used within the Applications Manager SQL*Plus (SQLP) program type script is shown below.
UNIX SQL*Plus Program Type Script Code
In a typical UNIX SQL*Plus program type script, the code that executes the program would look as follows (code in bold):
#!/bin/sh
#Copyright 2007 Automic Software GmbH
# $Header: /isa/devel/soport/so/dev/sostage/RCS/EXEC-SQLP,v 1.1
1996/01/22 09:42:26 soport Exp $
#
echo PATH Is
echo $PATH
if [ "$DEBUG" = "YES" ]; then
env
set -x
echo "in $0"
fi
if [ -f $program.sql ]; then
err=0
else
echo "file $program.sql does not exist"
exit 1
fi
echo sqlp `date`
echo $ORACLE_PATH
echo sqlplus -s @$program A$seq_no.lis $argu
echo "define so_outfile=A$seq_no.lis" >> $par
echo start $program >> $par
logtest=login.$$
echo "$login
spool $logtest
prompt got it
spool off
start $par A$seq_no.lis $argu
"|sqlplus -s
err=$?
if [ -f $logtest ]; then
rm $logtest
else
echo Could not login to sqlplus
err=1
fi
echo sqlp `date`
if [ -f A$seq_no.lis ]; then
mv A$seq_no.lis $file
fi
$AW_HOME/exec/FILESIZE $file $err
err=$?
exit $err
The code is a series of SQL commands that are passed into SQL*Plus.
Windows Program Type Script Code
In a typical Windows program type script, the code that executes the program would look as follows (code in bold):
@echo off
rem Copyright 2007 Automic Software GmbH
echo 'In EXECS'
echo 'calling'%program%
call %SQLOPER_HOME%\bin\oneline %SQLOPER_HOME%\run\%par%
call %SQLOPER_HOME%\c\ntspawn "%program% %args%"
if errorlevel 1 set err=%errorlevel%
The "call" command executes the program using the values stored in the 'args' variable.
To be able to kill a process launched by a Windows task (program type script), the process must be launched by the ntspawn executable as shown in the sample code above. Ntspawn launches the requested process and then waits for the process to exit. If a kill task is issued while the process is running, ntspawn will kill the process and return an error code. If the requested process is not launched with ntspawn, the kill task request will kill the cmd shell that launched the process, but most likely will not kill the launched process.
The syntax for ntspawn is:
Usage: ntspawn command [args]
Example: ntspawn c:\mydir\myexe.exe arg1 arg2 arg3
Option -l: Creates lockfile for Agent.
Option -t <seconds>: Time out value. If task runs longer than <seconds> task will be killed.
Option -i: Ignore DOS error file for exit code checking.
Option -s: Silent. Do not print process header information.
Windows SQL*Plus Program Type Script Code
In a typical Windows SQL*Plus program type script, the code that executes the program would look as follows (code in bold):
@echo off
rem Copyright 2007 Automic Software GmbH
echo 'In EXECS'
echo 'calling'%program%
call %SQLOPER_HOME%\bin\oneline %SQLOPER_HOME%\run\%par%
call %SQLOPER_HOME%\c\ntspawn "%program% %args%"
if errorlevel 1 set err=%errorlevel%
E:\AM\46NT_on_Dell\Master\exec>type sqlp.bat
if Not "%DEBUG%" == "YES" goto notdebug
set
echo on
echo in %0
:notdebug
if exist %program%.sql goto exists
echo "output file %program%.sql does not exist"
set err=1
goto end_of_it
:exists
echo in %0
echo plus31 -s @%program% A%seq_no%.lis %argu%
set err=0
echo define so_outfile=A%seq_no%.lis >> %par%
echo start %program% >> %par%
echo quit >> %par%
SET awsqlplus=c:\orant\bin\plus80.exe
echo %SQLOPER_HOME%\c\ntspawn "%awsqlplus% -s %db_login%/
passwd @%PAR% A%seq_no%.lis "
call %SQLOPER_HOME%\c\ntspawn "%awsqlplus% -s %LOGIN% @%PAR%
A%seq_no%.lis "
if errorlevel 1 set err=1
if exist %file% del %file%
if exist A%seq_no%.lis move A%seq_no%.lis %file%
if not exist %file% echo no output from %module%
if exist %file% call PRINTEM
:end_of_it
The code is a series of SQL commands that are passed into SQL*Plus.