The infx script service is used to execute your own scripts. The service takes care of setting up the environment, then executes your script, and records its output. You can use this service to create new scripts, or to re-use your existing scripts. The difference between a script and a utility is that a script can perform actions on the instance, not just get status information. For example, a utility might list user connections, where a script might be used to terminate user connections. For the purposes of this example, I will create a script that locates databases that are not logged, and turns their logging on. First, I will use the infx status service to output the required database information. Next, I will write a script that takes this output, and calls the infx backup service to run a fake back up and turn logging on. In real life, you would probably need to do a real backup as well.
get database infoFirst, we need to output the list of databases, and whether they have logging or not.. See the db list for more column information. bob001@bobii:/infx/local/script>infx status list=db_list vars=name+is_loggingmonitor_jgh1 1sqltest 0sysadmin 1write the shell scriptThe script must conform to the following rules, otherwise infx will not execute it.
Next, we will use the status output in our script to find the unlogged database, then call the infx fake backup service to change the logging mode. #!/bin/bashinfx status list=db_list vars=name+is_logging | while read dbname logging ; do if [ ! -z "$dbname" ] ; then if [ "$logging" -eq 0 ] ; then printf "infx backup type=fake unbuff=$dbname\n" infx backup type=fake unbuff=$dbname fi fidoneThat is all you need to put in this script. The infx script service will take care of setting the PATH and other variables. It will also record its output and status in the service log file. Now we call the script service, and pass it this scripts name. bob001@bobii:/infx/local/script>infx script script=dbloginfx backup type=fake unbuff=sqltestontape -s -F -L 0 -U sqltest -t /dev/nullArchive to tape device '/dev/null' is complete.Program over.Run the template again, and we see the logging mode changed. Lets add an option to this script to choose between buffered and un-buffered logging. To do this we will pass a parameter to the service, logmode=, the type of logging mode we want to set. To set unbuffered logging infx script script=dblog logmode=unbuffTo set buffered logging infx script script=dblog logmode=buffThe parameter from the command line will be automatically set in the environment of the script. The script should provide a default value, or produce an error message if something is missing. Changes highlighted. #!/bin/bashINFX_LOGMODE=${INFX_LOGMODE:-unbuff}; # default to unbuffered logginginfx status list=db_list vars=name+is_logging | while read dbname logging ; do if [ ! -z "$dbname" ] ; then if [ "$logging" -eq 0 ] ; then printf "infx backup type=fake unbuff=$dbname\n" infx backup type=fake $INFX_LOGMODE=$dbname fi fidoneThe command line parameters come from the infx service, direct into the environment of the script, with the variable name being prefaced with INFX_ to prevent name clashes. Use the config.ini file to set or modify any other environment variables you need for your script. |
