create a script
The difference between a script and a utility is that a utility just outputs set information via a template.
A script can used to perform actions on the instance, as well as get status information.
infx script
The infx script command is used to run your scripts. The command takes care of setting up the environment, manage log files etc, as well as executing your script
You can use this command to either create new scripts, or to re-use any of your existing scripts.
the script
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 command to output information about the databases. Next, the script will se the infx backup command to turn logging on.
We will use the infx status command in ad-hoc mode to output only the information we want.
1 2 3 4 |
$ infx status list=db_list vars=name+is_logging monitor_jgh1 1 sqltest 0 sysadmin 1 |
shell script
For the infx script command to accept your script, it must meet the following guidelines.
- Located in /infx/local/script
- File owner is informix
- Not be writable by others
- File mode set to executable
I will use the infx status output to find the unlogged databases, then call the infx backup type=fake command to change logging mode.
Script will be called /infx/local/script/dblog.
1 2 3 4 5 6 7 8 9 10 |
#!/bin/bash # script to find unlogged databases and turn their logging on infx 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 fi done |
That is all you need. The infx script command will take care of settings like PATH or INFORMIXDIR.
It will also record the output and status in the log file.
execute it
Pass the script name to the infx script command.
1 2 3 4 5 6 |
$ infx script script=dblog infx backup type=fake unbuff=sqltest ontape -s -F -L 0 -U sqltest -t /dev/null Archive to tape device '/dev/null' is complete. Program over. |
Now use the infx status command and check the status of each database.
1 2 3 4 |
$ infx status list=db_list vars=name+is_logging monitor_jgh1 1 sqltest 1 sysadmin 1 |
options
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 command, logmode=, to pass the type of logging mode we want to set.
Setting unbuffered logging
1 |
$ infx script script=dblog logmode=unbuff |
Setting buffered logging
1 |
$ infx script script=dblog logmode=buff |
parameters
You don’t need to parse the command line options in your script. The infx script command places the parameters into environment variables.
Environment variables are prefixed with INFX_, in our example the environment variable will be INFX_LOGMODE.
Yor scripts should provide default values, or produce error messages if something is missing.
1 2 3 4 5 6 7 8 9 10 11 |
#!/bin/bash INFX_LOGMODE=${INFX_LOGMODE:-unbuff}; # default to unbuffered logging infx 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 $INFX_LOGMODE=$dbname\n" infx backup type=fake $INFX_LOGMODE=$dbname fi fi done |