(SAT) Demo Application - displayhost

Source Code

#!/usr/bin/ksh
#=====================#
# SCRIPT: displayhost #
#=====================#

Host=`echo "${4}" | cut -f1 -d'	'`

{ mysql -v -v demo 2>&1 << !SQL
select 'satmysql silent';
select  *
  from  host
  where host='${Host}';
select 'satmysql no-fail silent disk';
select  disk\$id,disk\$size,type
  from  disk
  where host='${Host}';
!SQL
} | satmysql Host || echo "action {main}"
Comments

This script selects host/disk details for display.

Called by: main, addhost


Host=`echo "${4}" | cut -f1 -d'	'`
Set the variable Host to the first field of ${4}. This is necessary because the whole of the selected line is passed to displayhost when selecting the host from the main (Hosts) screen. This allows the same script to be used for main and addhost.
{ mysql -v -v demo 2>&1 << !SQL
The mysql command is used to access the demo database. The verbosity of mysql is set to -v -v. All output is directed to standard output so that it will be seen by satmysql. SQL satements are read until !SQL.
select 'satmysql silent';
When the host details are selected no messages are to be generated (silent).
select  *
  from  host
  where host='${Host}';
The details for the appropriate host are selected.
select 'satmysql no-fail silent disk';
When the disk information is selected from the demo database the result is to be put into the disk multi-column list and no messages are to be generated (silent). As it is possible that the result of the select will find no disks, the satmysql command is set to select the disks without failing (no-fail).
select   disk\$id,disk\$size,type
   from  disk
   where host='${4}';
The disk information for the host is selected to update the disk multi-column list. The "$" characters must be escaped to stop the shell seeing them as part of variable names. In screen procedures the ":" character is used instead of "$". For example: The screen item disk:id refers to the disk$id column in the database.
!SQL
} | satmysql Host || echo "action {main}"
The output from the mysql command is piped to satmysql. Any error messages generated by the SQL will be trapped and labeled with Host. For example: If the select satement is unable to select the host, satmysql will generate an "Unable to Select Host" message. If the select fails, the main (Hosts) screen is displayed.


Copyright © 2000 Adrian Davis.