2.6.23 Running the initialization script file
You can run a specific common script file before the job controller of JP1/Advanced Shell runs the job definition script file. By running a specific common script file before the job definition script file is run, you can specify the system-common initial settings, such as substituting values into variables, defining aliases, and moving data to the work directory.
- Organization of this subsection
(1) Overview of the initialization script file
The job controller handles the following files as script files:
Script files handled by the job controller |--- Job definition script file |--- External scripts | |--- External script files for the #-adsh_script command | |--- External script files for the . (dot) command | |--- Initialization script file | |--- .env files |--- [For Windows only] UNIX-compatible commands (script format)
The initialization script file is assumed to be a kind of external script file. Therefore, the job controller runs the initialization script file as an external script file, which is part of a job.
(2) Initialization script file
The initialization script file is a script file that the job controller runs for initialization when running the job definition script. If the INIT_SCRIPT_READ environment setting parameter is specified, the job controller reads and runs an initialization script file immediately before running the root job. However, the job controller outputs the KNAX6504-E message and terminates abnormally without running the initialization script in the following cases:
-
When the initialization script file does not exist
-
When a role required for execution is not granted
The following table describes how the behavior of the job controller changes depending on the specification of the INIT_SCRIPT_READ environment setting parameter and the status of the initialization script file.
No. |
Specification of INIT_SCRIPT_READ |
Status of the initialization script file |
Behavior of the job controller |
|
---|---|---|---|---|
Presence |
Role for reading |
|||
1 |
NO (Alternatively, this parameter is not specified.) |
-- |
-- |
Does not run the initialization script file. |
2 |
YES |
Not present |
-- |
|
3 |
Present |
A role for reading the file is not granted. |
||
4 |
A role for reading the file is granted. |
Runs the initialization script file. |
- Legend:
-
--: Not applicable
The system administrator is responsible for creating and setting up the initialization script file. The created initialization script file takes effect in only a specific path. The following table shows the valid path of the initialization script file.
No. |
Environment |
Valid path of the initialization script file |
---|---|---|
1 |
Windows (development environment) |
common-application-folder\HITACHI\JP1AS\JP1ASD\conf\adshinit_root.ash |
2 |
Windows (execution environment) |
common-application-folder\HITACHI\JP1AS\JP1ASE\conf\adshinit_root.ash |
3 |
UNIX |
/opt/jp1as/conf/adshinit_root.ash |
The job controller reads files in the order shown in the following table. Therefore, if an environment variable is set in both the environment file and the initialization script file, the setting specified by the initialization script file overrides the setting specified by the environment file.
Order |
File type |
Remarks |
---|---|---|
1 |
System environment file |
-- |
2 |
Job environment file |
-- |
3 |
.env file |
This file is read if YES is set for the KSH_ENV_READ environment setting parameter. |
4 |
Initialization script file |
This file is read if YES is set for the INIT_SCRIPT_READ environment setting parameter. |
5 |
Job definition script file |
-- |
- Legend:
-
--: Not applicable
In the initialization script file, specify the initialization processing to be performed when the job controller starts. Note that the following commands must not be used in the initialization script file:
-
Shell operation commands other than adshappexec
-
The following extended shell commands: adshecho, adshread, and adshjoberr
-
Extended script commands
The execution results of the commands specified in the initialization script file are output to the job execution log in the same way as for the commands specified in the job definition script file. The contents of the initialization script file are not output to the script image file.
(3) Notes
-
Do not change the contents of the initialization script file while jobs are running. Also, in the initialization script file, do not specify a process that changes the job definition script file.
-
Make sure that the following items match: 1) encoding of the initialization script file, 2) encoding of the job definition script file, and 3) the value of the LANG environment variable of the environment in which the job definition script is run. If the same setting is not specified in all of these environments, correct operation is not guaranteed.
-
If the processing of the initialization script file cannot continue due to an error that occurred in the file, the job controller abnormally terminates with a return code of 1 or the value set for the ADSH_JOBRC_FATAL environment variable. In this case, the job controller does not run the job definition script.
-
The behavior adopted when the root job is run from the initialization script file is as follows:
-
The root job run from the initialization script file does not run the job definition script file, and abnormally terminates with a return code of 1 or the value set for the ADSH_JOBRC_FATAL environment variable.
-
The job controller that is running the initialization script file continues processing.
-
-
The initialization script file does not support link files. Do not replace the initialization script file itself by a link file.
-
The initialization script file cannot be run by a debugger. To debug the initialization script file with the CUI or GUI debugger, run the file as a job definition script file in an environment in which NO is set for the INIT_SCRIPT_READ environment setting parameter.
-
Coverage information can be collected from only job definition script files. Therefore, to collect the coverage information of the initialization script file, run the file as a job definition script file.
-
The syntax of the initialization script file is not checked in syntax check mode. To check the syntax of the initialization script file, run the file as a job definition script file.
-
Function information arrays cannot be used in the initialization script file.
(4) Preparation for running the initialization script file
To run the initialization script file, use the following procedure:
-
Specify YES for the INIT_SCRIPT_READ environment setting parameter.
#-adsh_conf INIT_SCRIPT_READ YES
-
Place the initialization script file to be run in a valid path shown in Valid path of the initialization script file.
(5) Examples
Case in which the initialization script file terminates normally
-
Contents of the initialization script file
ADSH_SPOOL_JOBNAME=$( "${ADSH_DIR_CMD}basename" ${AJSJOBNAME} ) alias ls='"${ADSH_DIR_CMD}ls" -la' cd 'C:\ExecUser\init'
-
Contents of the job definition script file
#-adsh_step_start S01 echo "Job step start" #-adsh_step_end
-
Execution result
KNAX7901-I The job controller will wait for all asynchronous processes at the end of the job. KNAX0724-I The job ID was assigned. job ID=000003 --------------------------------------------------------------- Advanced Shell 11-10 [Information] Job ID : 000003 Spool directory : C:\ExecUser\result\spool\000003\ Date : 2016/08/19 EnvFile(system) : EnvFile(job) : C:\ExecUser\conf.ase Host name : HOST0001 [Environment variable from Automatic Job Management System] JP1JobName : adshexec.exe JP1JobID : 0000002362 JP1_USERNAME : jobadmin JP1UNCName : HOST0001 JP1NBQSQueueName: \\HOST0001\@SYSTEM JP1Priority : 64 AJSEXECID : @A665 AJSJOBNAME : /ExecUser/test/ASinit --------------------------------------------------------------- ******** JOB CONTROLLER MESSAGE ******** 14:51:19 000003 KNAX0091-I ADSH000003 The job started. 14:51:19 000003 KNAX7901-I The job controller will wait for all asynchronous processes at the end of the job. 14:51:19 000003 KNAX7902-I The job controller will run in non-tty stdin mode. 14:51:19 000003 KNAX6501-I This job will execute the initialization script file "C:\ProgramData\HITACHI\JP1AS\JP1ASE\conf\adshinit_root.ash". 14:51:19 000003 KNAX6126-I Execution of the command C:\PROGRA~2\Hitachi\JP1AS\JP1ASE\cmd\basename.exe for the function command substitution finished successfully. exit status=0 execution time=0.015s CPU time=0.015s 14:51:19 000003 KNAX6110-I Execution of the command ADSH_SPOOL_JOBNAME=ASinit (line=1) finished successfully. exit status=0 execution time=0.000s CPU time=0.000s 14:51:19 000003 KNAX6112-I Execution of the command alias (line=2) finished successfully. exit status=0 execution time=0.000s CPU time=0.000s 14:51:19 000003 KNAX6112-I Execution of the command cd (line=3) finished successfully. exit status=0 execution time=0.000s CPU time=0.000s 14:51:19 000003 KNAX6502-I Execution of the initialization script finished. 14:51:19 000003 KNAX0092-I ADSH000003.S01 step started. 14:51:19 000003 KNAX6112-I Execution of the command echo (line=2) finished successfully. exit status=0 execution time=0.000s CPU time=0.000s 14:51:19 000003 KNAX6597-I ADSH000003.S01 step succeeded. exit status=0 execution time=0.032s CPU time=0.015s 14:51:19 000003 KNAX0098-I ADSH000003 The job ended. exit status=0 execution time=0.063s CPU time=0.046s ******** Script IMAGE ******** ***** C:\ExecUser\test.ash ***** 0001 : #-adsh_step_start S01 0002 : echo "Job step start" 0003 : #-adsh_step_end ***** CONVERSION INFORMATION ***** ******** JOB SCOPE STDERR ******** KNAX6597-I ADSH000003.S01 step succeeded. exit status=0 execution time=0.032s CPU time=0.015s KNAX0098-I ADSH000003 The job ended. exit status=0 execution time=0.063s CPU time=0.046s ******** JOBSTEP OUTPUT ******** KNAX0719-I STEP. step number=0001 step name=S01 output destination=STDERR KNAX6380-I A job name will be added to the spool job directory of the root job. spool job directory="C:\ExecUser\result\spool\000003-ASinit\" KNAX7999-I Advanced Shell ended. exit status=0