1. Write an SQL script
Compile the SQL Execution script that DB2 needs to execute and place it on the AIX server.
The following is an example of crontest. SQL:
- Connect ToTemUserDb2admin using db2admin;
- Call P_TEST ();
2. Write the sh execution File
Write the sh file and place it on the AIX server. Modify the sh file to be executable.
Example: crontest. sh:
- PATH =/usr/bin:/etc:/usr/sbin:/usr/ucb: $ HOME/bin:/usr/bin/X11:/sbin :.
- Export PATH
- If[-S"$ MAIL"] # This is at Shell startup. In normal
- Then echo"$ MAILMSG"# Operation, the Shell checks
- Fi # periodically.
- # The following three lines have been added by UDB DB2.
- If[-F/home/db2admin/das/dasprofile]; then
- ./Home/db2admin/das/dasprofile
- Fi
- # The following three lines have been added by UDB DB2.
- If[-F/home/db2admin/sqllib/db2profile]; then
- ./Home/db2admin/sqllib/db2profile
- Fi
-
- # Execute SQL script
- Db2-svtf/home/db2admin/task/crontest. SQL-z/home/db2admin/task/crontest. log
Note: The first part of the sh file is to set the environment variables required for db2 execution (required), which can be modified according to the actual situation or directly stored in db2admin. directly copy the variables in the profile file.
- # Modifying the attributes of the sh File
- Chmod 777 crontest. sh
3. Configure crontab
Use the db2admin user to log on to the AIX system and run the crontab-e command to set scheduled tasks. For more information about crontab commands, see the description in the notes.
Example:
- # Set to execute the crontest. sh script at every day
- 00 02 ***/home/db2admin/task/crontest. sh
Save the disk and exit.